222k views
5 votes
Your classmate is frustrated because the code that was designed to add up her five quiz grades is not working properly.

What change would you suggest to your classmate based on this code?for (i=1;i<=5;i++){ sum=0sum=sum+i;}

User Licaomeng
by
7.1k points

1 Answer

5 votes

Answer:

sum = 0 must be before for loop. If inside for loop, it will keep resetting sum to 0 each iteration.

Step-by-step explanation:

hope this helps

User AlexBerd
by
7.1k points