# Error in my program.

• 10-03-2002
correlcj
Error in my program.
Greetings,
I have this code that when i input 5 scores it should average them and give me a grade instead of its percentage. Instaed of me summing say 5, 100% scores togther my grade should dispolay an A but the grade i always get is an F, go figure... anyways can anyone help me figure out why this is happening.

Code:

``` #include <iostream> #include <string>                //cin, cout, <<, >> using namespace std; int main() {         double score1, score2, score3,                         score4, score5, percentage;         char grade;         cout << "Input five test scores: ";         cin >> score1, score2, score3,                   score4, score5;         percentage = 5 / (score1 + score2 + score3 + score4 + score5);         if (percentage >= 90)                 grade  = 'A';        //grade must be 90 or better for an A         else if (percentage >= 80)        //grade must be 80 or better for an B                 grade  = 'B';         else if (percentage >= 70)        //grade must be 70 or better for an C                 grade  = 'C';         else if (percentage >= 60)        //grade must be 60 or better for an D                 grade  = 'D';         else                 grade  = 'F';        //anything less than 60 % is failing         cout << "\nYour letter grade is " << grade << "\n";         return percentage; }```
• 10-03-2002
Cshot
Two problems:
cin >> score1, score2, score3,
score4, score5;
Your compiler should've given you warnings. If you ignore them, you may see more F's ;)

percentage = 5 / (score1 + score2 + score3 + score4 + score5);
should be
(score1 + score2 + score3 + score4 + score5) / 5;
• 10-03-2002
Prelude
>cin >> score1, score2, score3, score4, score5;
Uh, no. This won't work as you expect, try this instead:

cin >> score1 >> score2 >> score3 >> score4 >> score5;

>percentage = 5 / (score1 + score2 + score3 + score4 + score5);
This is your problem, the additions are performed first, but you still divide 5 by the total. It should be the other way around:

percentage = (score1 + score2 + score3 + score4 + score5) / 5;

-Prelude
• 10-03-2002
correlcj
Master Yoda!
Thanks!
Youo wouldn't believe me if I told you so but I am embarrased to say I looked that over for a long time last night. For the life of me I could not see it until now... THANK YOU!
;)
No more F's now.