Hello!
The main problem revolves around this line of code:
1.] final = (grade1 + grade2 + grade3 + grade4 + grade5)/5;
You are calculating the average. Later in the code, in your if/else statements, this inevitably leads to two issues. One has to do with the value that your final variable holds. The other has to do with the way you have written the statements.
2.] if (91 <= final <= 100)
First of all, if you write it like this, which should rather be
if (final == 100)
{
....
}
else if (final >= 90)
{
....
}
only this first statement will execute, hence A+ is output all the time. The reason is, that, no matter how high the sum of your grades, since you calculate the average, your number will always be lower than or equal to 100. And lower than any passing grade besides. So, the first thing to do is to change:
final = (grade1 + grade2 + grade3 + grade4 + grade5);
To only hold the sum of all grades. The next step is to change your if/else statements according to my example. If you further wish to have someone using your program input a value if the original value is invalid, add this to your code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
cout << "What is your first grade? ";
cin >> grade1;
while (grade1 < 0 || grade1 > 100)
{
cout << "Error: Enter a valid grade: ";
cin >> grade1;
}
cout << "What is your second grade? ";
cin >> grade2;
// so on so forth
|
If you wish to calculate the average of all grades, you should add another variable, called averageGrade. (Or whatever you wish to name it). To calculate the average then all you need to do is write:
averageGrade = final / 5;
cout << "Your average grade is: " << averageGrade << endl;
What you should do besides that is to initialize your variables. You can't assume that all of them will receive a default value of 0, which can lead to wrong results in calculations. ;-)