### If else statement

Hello,

i been trying to get the outcome of the grades to show a letter grade but its not working properly and i tried lots of way and still stuck.

for example, if i were to enter 90 for 5 grades and it comes to be an A and if i were to enter 5 grades of 80 it still comes out to be A. no matter how much i look at the program it seems good to me but if u guys could spot the mistake please let me know.

thank you

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445`` ``````]#include using namespace std; float total(int[],int); int main() { const int num = 5; int i, grade[num]; int final; for (i = 0; i < num; i++) { cout << "Enter a grade: "; cin >> grade[i]; } cout << "\nThe average of the grades is " << total(grade,num) << endl; { if (final >= 90) cout << "Your letter grade is A" << endl; else if (final >= 80 ) cout << "Your letter grade is B" << endl; else if (final >= 70) cout << "Your letter grade is C" << endl; else if (final >= 60) cout << "Your letter grade is D" << endl; else cout << "Your letter grade is F" << endl; } system("pause"); return 0; } float total(int grade[], int i) { int total=0; int final; for(int j=0; j
In the total() function the returned float is final.

However in your code you don't put the returned value into anything, so you're just comparing against your uninitialized 'int final;' on line 9.

So you just need to do:
 `` `` ``final = total(grade, sum);``

You also need to change your final variable in the main function to a float, not an int.
Last edited on
oh i see. i got it thx for your help
Topic archived. No new replies allowed.