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;
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.
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.