Feb 1, 2017 at 3:17am UTC
this is an assignment i am currently having trouble with. I get no outputs after i enter the letter grade. I was wondering if any one could explain why there isn't a output? Also First programming class without any experience.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
using namespace std;
int main()
{
char grade
cout << " Please enter your letter grade" << endl;
cin >> grade;
if (grade == 'A' || grade == 'a' )
{
cout << " Excelent Work" << endl;
}
if (grade == 'B' || grade == 'b' )
{
cout << "Above Average Work" << endl;
}
if (grade == 'C' || grade == 'c' )
{
cout << "Average Work" << endl;
}
if (grade == 'D' || grade == 'd' )
{
cout << "Below Average Work" << endl;
}
if (grade == 'F' || grade == 'f' )
{
cout << " You Are Failing" << endl;
}
return 0;
}
Last edited on Feb 1, 2017 at 3:44am UTC
Feb 1, 2017 at 11:40am UTC
I understand now. I missed the semi colon
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#include <iostream>
using namespace std;
int main()
{
char grade;
cout << "Please enter your letter grade in the class" << endl;
cin >> grade;
if (grade == 'A' || grade == 'a' )
{
cout << "Excelence Work" << endl;
}
else if (grade == 'B' || grade == 'b' )
{
cout << "Above Average Work" << endl;
}
else if (grade == 'C' || grade == 'c' )
{
cout << " Average Work" << endl;
}
else if (grade == 'D' || grade == 'd' )
{
cout << " Below Average Work" << endl;
}
else if (grade == 'F' || grade == 'f' )
{
cout << " You Are Failing" << endl;
}
else
{
cout << " No such grade /n" << endl;
}
return 0;
}
It still wont work it say i have an unidentified token
Last edited on Feb 1, 2017 at 11:48am UTC
Feb 1, 2017 at 11:53am UTC
It worked. I get what you both were saying Thank you
i just didnt know i could put a question mark for char grade
Feb 1, 2017 at 12:02pm UTC
Good news.
The reason for the '?' is just to initialize it so that if you had to print the grade out and a ? appeared you know nothing has changed it so obviously something is wrong, but under control. Chose any character you like. Initialization gets over the problem of undefined/unrecognized/uninitialized variable behavior. It doesn't solve the ; problem which is separate.
Last edited on Feb 1, 2017 at 12:04pm UTC
Feb 1, 2017 at 12:17pm UTC
Thank You Kemort. That makes sense now. I shouldn't have a problem doing the rest of the program asking for similar results