Switch Statements :(

Hi there just having a little trouble getting this switch statement to work. Im using bloodshed c++ and tried to compile the following:

The errors im getting is:

cpp:20: error: case label `'A'' not within a switch statement
cpp:22: error: break statement not within loop or switch
cpp:24: error: case label `'B'' not within a switch statement
cpp:26: error: break statement not within loop or switch
cpp:28: error: case label `'C'' not within a switch statement
cpp:30: error: break statement not within loop or switch
cpp:32: error: case label `'D'' not within a switch statement
cpp:34: error: break statement not within loop or switch

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
// Pg 164 Ex 4.4 Qu 1.

#include <iostream>
using namespace std;

int main ()

{
    
    char letGrad, ch;
    
    cout << "Please enter a character: ";
    
    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;
 
}


edit: added details.
Last edited on
semicolon after switch is a no no
any ideas guys?
kevin alreay told you that a semicolon should not be there after a switch..
 
switch (letGrad);

closed account (z05DSL3A)
Did you not read kevinchkin's reply?

line 16 should be switch (letGrad) and not switch (letGrad);

Edit: too late
Last edited on
Topic archived. No new replies allowed.