### for loop

i have assignment about for loop and this is the instruction for the program
(Prompts a user for number of exams taken
Uses FOR Loop to interate (loop) up to the value entered above, example: 3 exams taken, FOR loop should interate 3 times.
In each iteration, prompt user for exam grade
Calculates Average exam grade from values entered
Outputs both numerical and letter grade to screen
Has error checking in case user enters 0 for number of exams taken
)
this is what i have done,but still didn't work

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include #include using namespace std; int main() { int numExams, loop; double totalGrade,sum; double averageGrade; double G; char letterGrade; cout << setprecision(2) << fixed << showpoint; cout << "Enter Number of Exams Taken: "; cin >> numExams; cout << endl; for(loop=numExams;loop>0;loop--) { cout <<"Enter Exam grade: "; cin >>G; sum=numExams+sum } averageGrade = totalGrade / numExams; cout << "\n\nAverage: " <= 90) letterGrade = 'A'; else if (averageGrade >=80) averageGrade = 'B'; else if (averageGrade >= 70) letterGrade = 'C'; else if (averageGrade >= 60 ) letterGrade = 'D'; else letterGrade = 'F'; cout << endl; cout <<"Number of Exams Taken: " << numExams << endl; cout <<"Average Grade: " << averageGrade << endl; cout << "Letter Grade: " << letterGrade << endl << endl; return 0; } }``````
I think your formula is the problem
`sum=numExams+sum`
Besides the fact that it is missing ; it dosen't calculate anything related to the grade
You have variables totalGrade and sum, you never assigned value to totalGrade so from your code I think those are pretu much the same variables.
So you should lose totalGrade and use this formula
`sum += G`
And for average
`averageGrade = sum / numExams;`
That should fix the problem.

P.S. You forgot to check if input is zero.
Topic archived. No new replies allowed.