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

Heres an algorithm that reads all the numbers from a file,displays them and then

ID: 3614800 • Letter: H

Question

Heres an algorithm that reads all the numbers from a file,displays them and then closes the file: Declare InputFile numberList Declare Integer i Open numberList "number_list.dat" Display "Here are the numbers:" While NOT eof (numberList)    Read NumberList i    Display i End While Close myName Heres my question...From this algorithm that i wrote, i haveto modify it so that it adds all of the numbers read from the fileand displays their total I have done it a few times but what i did just seems toosimple. some help would be great Thanks Heres an algorithm that reads all the numbers from a file,displays them and then closes the file: Declare InputFile numberList Declare Integer i Open numberList "number_list.dat" Display "Here are the numbers:" While NOT eof (numberList)    Read NumberList i    Display i End While Close myName Heres my question...From this algorithm that i wrote, i haveto modify it so that it adds all of the numbers read from the fileand displays their total I have done it a few times but what i did just seems toosimple. some help would be great Thanks

Explanation / Answer


Declare InputFile numberList Declare Integer i
Declare Integer sum
Open numberList "number_list.dat" Display "Here are the numbers:"
Set sum to 0
While NOT eof (numberList)    Read NumberList i
   Add i to sum
   Display i End While
Display sum
Close myName