Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following code totals the values in two integer arrays: intnumberarray1 and

ID: 640448 • Letter: T

Question

The following code totals the values in two integer arrays: intnumberarray1 and intnumberarray2. both arrays have 25 elements. will the code print correct sum of values for both arrays? Why or why not?

Dim intTotal as integer
For intCount = 0 to 24
intTotal += intNumberArray1(intCount)
Next intCount

MessageBox.Show("Total for intNumberArray1 is " & intTotal.ToString())

For intCount = 0 to 24
intTotal += intNumberArray2(intCount)
Next intCount

MessageBox.Show("Total for intNumberArray2 is " & intTotal.ToString())

Explanation / Answer

The following code totals the values in two integer arrays: intnumberarray1 and intnumberarray2. both arrays have 25 elements. will the code print correct sum of values for both arrays? Why or why not?

Dim intTotal as integer = 0;
For intCount = 0 to 24
intTotal += intNumberArray1(intCount)
Next intCount

MessageBox.Show("Total for intNumberArray1 is " & intTotal.ToString())
intTotal = 0;
For intCount = 0 to 24
intTotal += intNumberArray2(intCount)
Next intCount

MessageBox.Show("Total for intNumberArray2 is " & intTotal.ToString())


It will not print correct sum of values for both arrays are intTotal is not initialized with zero.
make first statement as follows.
Dim intTotal as integer = 0
After summing first array again reset intTotal to zero.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote