I am currently working on a zork-like game where a character is confronted with choices (mostly yes or no, or left or right) that helps move the character on through the game. My question is, how do I validate a character's response so that their response determines the outcome.
I'm currently using if, else if, and else statements, but it seems to be strictly numerical. How do I validate non-numerical values?
void response_A()
{
int response;
cin >> response;
//Action for Yes Response
if (response == 'Y' || 'y')
{
cout << "Great! I sure love adventures!" << endl;
cout << "Where should we go?" << endl;
cout << "(L/R)" << endl;
}
//Action for No Response
else if (response == 'N' || 'n')
{
cout << "Too bad... This is the game." << endl;
cout << "We're going to explore anyway.";
}
//Action for Incorrect Response
else
{
cout << "Bitch please... I said y or n.";
response_A();
}
}
Okay thank you. But when I run the program, even using char response; , I can place any input and it will still run the first if() statement, without considering if(), else if(), or else(). Do you get what I mean? It basically ignores the if() statement and jumps directly to cout << {"dialogue"}, regardless of what cin is.