Menu chooser - rewrite it with enumeration

Hi. I am reading the book "Beggining C++ Game Programming" by Michael Dawson and i have stumbled upon an exercise here. There was a Menu Chooser program that i wrote before for practice and now there is an exercise that i have to rewrite it using an enumeration to represent difficulty levels. Here is the basic Menu Chooser program. Any ideas? I have tried to rewrite it, but i came upon some compiler errors.

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
// Menu Chooser
// Demonstrates the switch statement

#include <iostream>
using namespace std;

int main()
{
    cout<<"Difficulty levels\n\n";
    cout<<"1 - Easy"<<endl;
    cout<<"2 - Normal"<<endl;
    cout<<"3 - Hard"<<endl;
    
    int choice;
    cout<<"Choice: ";
    cin>>choice;
    
    switch (choice)
    {
           case 1:
                cout<<"You picked Easy."<<endl;
                break;
           case 2:
                cout<<"You picked Normal."<<endl;
                break;
           case 3:
                cout<<"You picked Hard."<<endl;
                break;
           default:
                   cout<<"You made an illegal choice."<<endl;
    }
    system ("PAUSE");
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
enum { Easy = 1, Normal, Hard };

    switch (choice)
    {
           case Easy:
                cout<<"You picked Easy."<<endl;
                break;
           case Normal:
                cout<<"You picked Normal."<<endl;
                break;
           case Hard:
                cout<<"You picked Hard."<<endl;
                break;
           default:
                   cout<<"You made an illegal choice."<<endl;
    }


Shows us the version you tried to write with the enum and also paste the compiler errors.
thank you vlad from moscow, i compiled it and it worked! Cheers!
@L B i now know where i had my mistake, i fixed it and it worked.
Topic archived. No new replies allowed.