To debug the program and find out why the average is not printing out correctly, the most appropriate variable to print out is sum.
Here is why:
- The variable
temp
correctly stores each individual grade input, but it does not directly contribute to the final average calculation in the way intended. - The variable
x
is just looping through a range and won't help you understand the accumulated sum. - The variable
grade
will give you the final output, but if thesum
is incorrect, thengrade
will also be incorrect.
The issue in your code arises from this line:
sum = temp + 1
This line is incorrectly adding 1
to temp
instead of accumulating the grades together.
So, printing sum
would help you identify that the accumulated sum is incorrect, while your calculation for the average is based on that incorrect sum.