somethings wrong

#include <iostream>
using namespace std;

int main ()
{
double total_points=0, average;
double grade;
int i=1;

while (i<5)
{
cout<<"Please enter the results of your exams"<<endl;
cin>>grade;
i=i+1;
}

total_points =+ grade;
cout<<"The sum of your grades is: "<< total_points<<endl;
average = total_points/4;
cout<<"The average of your grades is: "<<average<<endl;


if (average>0.36)
{
cout<<"You have got a D-"<<endl;
}

else if (average>0.67)
{
cout<<"You have got a D"<<endl;
}

else if (average>1.00)
{
cout<<"You have got a D+"<<endl;
}

else if (average>1.33)
{
cout<<"You have got a C-"<<endl;
}

else if (average>1.67)
{
cout<<"You have got a C"<<endl;
}

else if (average>2.00)
{
cout<<"You have got a C+"<<endl;
}

else if (average>2.33)
{
cout<<"You have got a B-"<<endl;
}

else if (average>2.67)
{
cout<<"You have got a B"<<endl;
}

else if (average>3.00)
{
cout<<"You have got a B+"<<endl;
}

else if (average>3.33)
{
cout<<"You have got a A-"<<endl;
}

else if (average>3.67)
{
cout<<"You have got a A"<<endl;
}

else
cout<<"You have failed to pass this class"<<endl;

cout<<"The grading system used in this course is as the following:"<<endl;

cout<<"A (4.00)"<<endl;
cout<<"A- (3.67)"<<endl;
cout<<"B+ (3.33)"<<endl;
cout<<"B (3.00)"<<endl;
cout<<"B- (2.67)"<<endl;
cout<<"C+ (2.33)"<<endl;
cout<<"C (2.00)"<<endl;
cout<<"C- (1.67)"<<endl;
cout<<"D+ (1.33)"<<endl;
cout<<"D (1.00)"<<endl;
cout<<"D- (0.67)"<<endl;
cout<<"F (0.36)"<<endl;

return 0;


the total_points arent calculated correctly. it just shows me the last input of grade. so if i last put 1.3 thats the total sum. i dont know how to fix it.
I noticed that:
total_points =+ grade; s/b total_points += grade;
yea i changed that but still have the same problem
Just helped someone with a similar problem not 5 minutes ago...strange...

1
2
3
4
5
6
7
8
while (i<5) //this loop only runs 4 times(since i is already equal to 1)
{
cout<<"Please enter the results of your exams"<<endl;
cin>>grade;
i=i+1;
}

total_points =+ grade; //incorrect, move this somewhere else 


Say heres your input
1 3 4 2 5


The loop does the following:

Please enter the results of your exams
1 //grade is now equal to 1
Please enter the results of your exams
3 //grade is now equal to 3
Please enter the results of your exams
...

Notice something? You dont actually add grade onto total until the loop ends. This means grade only holds the last input received, in this case 5. You need to add the variable onto total before the while loops again.
Last edited on
maybe we are in the same course ?
i understand what you are saying but where to move it...because when i move it up the variable grade is not initialized. and it displays an error.
i think i got it.....i juts put that inside the while loop...let me just check it.
Yep, inside the while loop would make the program run correctly.
thanks man i appreciate it.
Topic archived. No new replies allowed.