Original Post
Hi guys wasnt sure whether to put this in game programming or not but seen as its only basic console stuff i chose to put it in here. sorry if its in wrong place! im currently reading the book "beginning C++ Game Programming" and at the end of chapter 2 it asks me to rewrite a program using enumarators, but im unsure what it wants me to do :| heres the original code: now im assuming it wants me to use enumarators as my choice for the switch cases so im trying to do the following but it wont compile properly so im unsure as to what it wants me to do. the question is: "Rewrite the menu chooser program from this chapter using an enumeration to represent difficulty levels." heres the code i have: as you can see im trying to get one of the enum numbers into the switch case, but ive no idea if this is what it wants or how to impliment my idea :( any ideas? if anyone knows where the exercise answers are to this book could they paste a link too? ive had a search around and cant find anything. any help appreciated lonefox
#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;
default:
cout << "You made an illegal choice.\n";
}
return 0;
}
#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";
enum difficulty { EASY = 1, NORMAL , HARD};
int mydiff;
cout << "enter a number 1 to 3 for difficulty level: " << endl;
cin >> mydiff;
difficulty selection = mydiff;
switch (selection)
{
case 1:
cout << "You picked Easy.\n";
break;
case 2:
cout << "You picked Normal.\n";
break;
case 3:
cout << "You picked Hard.\n";
break;
default:
cout << "You made an illegal choice.\n";
}
return 0;
}