I am new to C++ and am making a simple text RPG, anyway, The scenario is I have a "welcome" screen with choices 1-3, and have a simple IF statement to check them, here:
int choice;
std::cout << "--> ";
std::cin >> choice;
if(choice == 1) {
//..
That works fine, but if someone enters a letter as selection (instead of 1, 2 or 3) it'll become "-392493492"or something and crash the program. So I came up with:
char choice;
std::cout << "--> ";
std::cin >> choice;
if(choice == 1) {
//..
This works kinda fine, but when I enter a number it seems to skip the IF statements completely.. Is the char "1" the same as the number 1?
I get a compiler error with this (ISO-CPP or something):
if(choice == "1")
So how on earth do I see if they entered 1-3 correctly!?