Code:
int main()
{
char userChoice;
int userNumber;
char N;
char S;
char E;
char W;
char continueChoice;
cout<< "Welcome to the game!"<< endl;
cout<< "You just woke up with amnesia" <<endl;
cout<< "Dizzy and tired, you look around" <<endl;
cout<< "You are in a forest" <<endl;
cout<< "A sign says Beware! Leave this forest A.S.A.P!!!" <<endl;
do
{
cout<< "You have " << health << " health points" <<endl;
cout<< "What direction do you want to walk to?" << endl;
cout<< "(Press N, S, E, or W to move North, South, East, or West)" <<endl;
cin>> userChoice;
if ((userChoice == 'N') || (userChoice == 'n'))
{
userNumber = 1;
}
else if ((userChoice == 'S') || (userChoice == 's'))
{
userNumber = 2;
}
else if ((userChoice == 'E') || (userChoice == 'e'))
{
userNumber = 3;
}
else if ((userChoice == 'W') || (userChoice == 'w'))
{
userNumber = 4;
}
switch (userNumber)
{
case 1:
{
RmOne(userNumber);
}
break;
case 2:
{
RmTwo(userNumber);
}
break;
case 3:
{
RmThree(userNumber);
}
break;
case 4:
{
RmFour(userNumber);
}
break;
default:
cout<< userChoice << " is not a valid choice" <<endl;
break;
}
cout<< "Do you want to continue searching for a way out of the forest? (Press Y to continue, N to quit)" <<endl;
cin>> continueChoice;
}
while ((continueChoice=='Y') || (continueChoice=='y'));
return 0;
}
The first time I loop, any key other than NSEW will bring me to the first userChoice that I inputted.
For example, if I start the program from the beginning and my userChoice is N, it'll run correctly and when I select Y to continue program and M as my next userChoice, it'll go to my case 1 rather than the default.