Output Message Problem

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
What did you enter? If I enter a to f I get the proper output. Only when I enter sth. else it doesn't show.

BTW on line 8 a ; is missing.

OUTPUT
1
2
3
Please enter your letter grade
d
Below Average Work
closed account (48T7M4Gy)
Line 8 is missing a ; But as Thomas1965 pointed out it worked once that was fixed up. However here's a couple of simple improvements.

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
#include <iostream>

using namespace std;

int main()
{
    
    char grade = '?'; //<-- good idea to initialise
    
    cout << " Please enter your letter grade" << endl;
    cin >> grade;
    
    
    if (grade == 'A' || grade == 'a')
    {
        
        cout << " Excellent Work" << endl;
    }
    
    else if (grade == 'B' || grade == 'b') // <-- use else if structure
    {
        
        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"; // <-- Picks up error
    
    return 0;
    
}
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
It worked. I get what you both were saying Thank you
i just didnt know i could put a question mark for char grade
closed account (48T7M4Gy)
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
Thank You Kemort. That makes sense now. I shouldn't have a problem doing the rest of the program asking for similar results
closed account (48T7M4Gy)
@MrJ

BTW Instead of grade == 'F' || grade == 'f' etc if you add a line after cin >> grade to convert the input to upper case you can avoid all the ||'s ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cout << " Please enter your letter grade" << endl;
    cin >> grade;
    
    grade = toupper(grade);
   
    if (grade == 'A')
    {
        cout << " Excellent Work" << endl;
    }
    
    else if (grade == 'B') // <-- use else if structure
    {
        cout << "Above Average Work" << endl;
    } etc etc

Topic archived. No new replies allowed.