To debug the program and find out why the average grade is not printing out correctly, the most appropriate variable to print would be:
sum
The reason for this choice is that sum
is the variable that is being calculated to find the total of the grades entered. In the code, the issue arises from the line:
sum = temp + 1
This line incorrectly adds 1 to the current grade input (temp) instead of adding it to the cumulative sum of the grades. Printing sum
after the loop will show whether it has been calculated correctly or not. By examining its value, you can determine if the error is due to the logic in accumulating grades.