Im making a simple rock paper scissors game and I need to use the enumeration data structure. My problem is that i cannot compile the following code because of an invalid conversion from int (userInput) to Throws (userThrow).
enum Throws {R, P, S};
int userInput;
cout << "What is your throw : ";
cin >> userInput;
Throws userThrow = userInput;
Help?!
You can do it like this:
int userInput;
std::cin >> userInput;
Throws userThrow = static_cast<Throws>(userInput);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With