So, I am a complete beginner with the c++ language, and I am working on an exercise in the book "Beginning C++ Through Game Programming", specifically the first exercise on chapter 3. It wants me to create a "Difficulty Choosing Program" using std::cout
and the switch
statement, however I found an issue when trying to use std::cin
to input a variable (myDifficulty
) of the enumeration type difficulties
, where I get the error above under my >>
. Here is my code:
#include <iostream>
int main()
{
enum difficulties {EASY = 1, NORMAL, HARD, EXTREME};
difficulties myDifficulty;
std::cout << "Easy\nNormal\nHard\nExtreme\n";
std::cin >> myDifficulty;
switch (myDifficulty)
{
case 1:
std::cout << "You have chosen Easy as your difficulty." << std::endl;
break;
case 2:
std::cout << "You have chosen Normal as your difficulty." << std::endl;
break;
case 3:
std::cout << "You have chosen Hard as your difficulty" << std::endl;
break;
case 4:
std::cout << "You have chosen Extreme as your difficulty. Good luck!" << std::endl;
break;
}
system("pause");
return 0;
}
If anyone can help, thank you. Also, if there is anything wrong with my code (how it looks etc.) feedback would be appreciated greatly!
P.S This is my first question. :)