Zork-esque game : Am I using if() correctly?

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?

[code]

int main()
{
using namespace std;

// Introduction
cout << "Welcome to #Dead!" << endl;
cout << " " << endl << " " << endl;
cout << "You enter an unknown place..." << endl << " " << endl;
cout << "Shall you explore?" << endl << " " << endl;
cout << "(y=Yes/n=No)" << endl << " " << endl;

void response_A();

//First Response
response_A();

return 0;

}

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();
}
}

Thank you.
Last edited on
Declare with 'char' instead of 'int' when you need letters
int can only register numbers
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.
Last edited on
Use

if (response == 'Y' || 'y') incorrect
this means everything inbetween i believe
ASCII if you want to look it up

if (response == 'Y' || response == 'y') correct


void response_A();
should be really be placed above int main()
Thank you sir. I appreciate it.
Topic archived. No new replies allowed.