For Loop Help

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
system("CLS");
double grade, test, number, average, sum;
int counter = 1;

cout << "Enter Number of Exams Taken: ";
cin>>test;

for (number=test;number>0;number--)
{
cout << "Enter Grade for Exam "<<counter<<": " ;
counter=counter+1;
}

cout<<fixed<<showpoint;
cout << setprecision(2);

average=sum/test;

cout<<"The Exam Sum of "<<sum<<" divided by "<<test<<" = "<<average<<"%"<<endl;

if(average>=90)
cout<<"You have an A";
else if (average>80)
cout << "You have a B";
else if (average>70)
cout << "You have a C";
else if (average>60)
cout << "You have a D";
else if (average<60)
cout <<"You have an F";

return 0;
}

I need the calculations for sum to calculate each time I enter a grade, so if I put that I have taken 3 tests, and then enter 100, 100, 100. It would equal 300, then do the average? Right now it is either taking the sum of the last entered test grade. HELP! Thanks.
take the sum calculation within the for loop. A present it is just adding the last grade entered.

 ``12345678`` ``````sum = 0; for (number=test;number>0;number--) { cout << "Enter Grade for Exam "<>grade; sum += grade; }``````

Topic archived. No new replies allowed.