Original Post
Hello! So I am reading this book called Beginning C++ Game Programming by Michael Dawson. I just finished reading Chapter 2 about loops and I got stuck in one of the exercises. I am asked to change the original code to use enumerator, but I can't get it to work. I get error message on compiling saying "Line 17 - no match for 'operator>>' in 'std::cin >> mychoice' ". As far as I can tell, my cin command is somehow bugged. The code works fine without it. I use Dev-C++ to compile my code, as the book recommends it. So what is the problem? Here is the original code: My code:
// 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;
default:
cout << "You made an illegal choice.\n";
}
return 0;
}
// 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";
enum choice {easy = 1, normal, hard};
choice mychoice = easy;
cout << "Choice: ";
cin >> mychoice;
switch (mychoice)
{
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";
}
system("pause");
return 0;
}