The Switch Statement

hi, im tryin to get a swtich statement equivalent for the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
if (letGrad == 'A')
    cout << "The numerical grade is between 90 and 100";
else if (letGrad == 'B')
    cout << "The numerical grade is between 80 and 89.9";
else if (letGrad == 'C')
    cout << "The numerical grade is between 70 and 79.9";
else if (letGrad == 'D')
    cout << "How are you going to explain this one?";
else
{
    cout << "Of course I had nothing to do with the grade.";
    cout << "\nThe professor was really off the wall.";
}




The errors i am getting are:

error: case label `'A'' not within a switch statement

error: expected `;' before "break"

I'm a bit unsure of where to put objects n such. Here is my attempt:


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
#include <iostream>
using namespace std;

int main ()

{
    
    char letGrad;
    
    cin >> letGrad;
    
    switch (letGrad);
    
    {
    
case 'A':
    cout << "The numerical grade is between 90 and 100"
    break;
    
case'B':
    cout << "The numerical grade is between 80 and 89.9" <<;
    break;
    
case 'C':
    cout << "The numerical grade is between 70 and 79.9" <<;
    break;
    
case 'D':
    cout << "How are you going to explain this one?" <<;
    break;
    
    }
    
    cout << "Of course I had nothing to do with the grade.";
    
    cout << "\nThe professor was really off the wall.";
    
 
 system ("pause");
 
 return 0;
 
}

At line 12 you have an extra semicolon
Dear Jayray23
first of all line#12 has an extra semicolo.
line # 17 u did not end this line with semicolon so put it.
line# 21,25,29 has same problem.
You should write endl before semicolon or u should finsh(delete) the insertion operators from the end of these lines.

i think then it will work.
Thanks for your responses. My code was kinda lousy to start off with (must of been the midnight blues).

Thanks for your help i got it running.

Cheers.
Topic archived. No new replies allowed.