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
Determines letter grade based on numerical grade
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <iomanip>

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: " <<averageGrade;
    

        
            
 
    if (averageGrade >= 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.