Please Help! Beginning C++ Through Game Programming Menu Chooser Excercise

I'm going through the book Beginning C++ Through Game Programming and I am dealing with an exercise that wants me to rewrite the menu chooser program that I created in the chapter. However, instead of using a switch/case it wants me to use an enumeration to represent the difficulty levels. My variable choice has to stay as an int. I have found several answers to this, but they just involve placing enum GAMEMODE{EASY, NORMAL, HARD} at the top of the program, but that doesn't actually use the enum since the switch is still in the program. I'm just looking for an honest answer. I'm new to C++ and I'm looking to do things the right way and understand it. Here is the original code

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

#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)
    {
        case 1:
            cout << "You picked Easy.\n";
            break;
        case 2:
            cout << "You picked Normal.\n";
            break;
        case 3:
            cout << "You picked Hard.\n";
            break;
        case 4:
            cout << "You made an illegal choice.\n";
    }

    return 0;
}


I need the program to do what it does right now without the switch, but instead with an enumeration. How do I accomplish this?
I hope std::strings aren't out of the scope of your learning material:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

enum Difficulty {EASY=0, NORMAL, HARD};

int main(int argc, char* argv[]) {
	std::string difficulties[3] = {"Easy", "Normal", "Hard"};
	Difficulty choice = EASY;

	std::cout << "The difficulty you chose:\t" << difficulties[choice] << std::endl;

	std::cin.get();
	return 0;
}


Note, this doesn't ask the user for input. It's just one way of using enumerators.
Topic archived. No new replies allowed.