simple switch statement not working correctly

New to programming in general. I get the idea but the outcome isn't correct. every time I enter a number, it keeps going to the default cout.

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()
{


   cout << "Difficulty Levels\n\n";
   cout << "1 - Easy\n";
   cout << "2 - Normal\n";
   cout << "3 - Hard\n\n";

   int choice;
   cout << "Choice: ";
   cin >> choice;

   switch (choice)
   {
    case1:
        cout << "You picked Easy.\n";
        break;
    case2:
        cout << "You picked Normal.\n";
        break;
    case3:
        cout << " You picked Hard.\n";
        break;
    default:
        cout << "You made an illegal choice.\n";

   }





return 0;
}


It's from a book I'm pretty sure I got the code right but using codeBlocks is quirky. Sometimes I have to restart another project to execute the code correctly. In this case, it just doesn't come out right. Is it better to use visual studio?

Thanks for the advice.
A compiler says:
 In function 'int main()':
23:5: warning: label 'case1' defined but not used [-Wunused-label]
26:5: warning: label 'case2' defined but not used [-Wunused-label]
29:5: warning: label 'case3' defined but not used [-Wunused-label]

Do note that case1 is not same as case 1
As Homer Simpson would say. 'Doh'

Duh thanks should have known. In most cases a number directly afterward is mostly defined as a variable.

sure enough, case is highlighted blue.
Last edited on
Topic archived. No new replies allowed.