int main()
{
char ansPlay;
cout<<"Welcome! Would you like to play a game of Roulette? \n<Y>es or <N>o"<<endl;
while(1)
{
cin>>ansPlay;
if(ansPlay == 'N' || ansPlay == 'n')
{
cout<<"Too bad. See you next time.";
cin.get();
return 0;
}
elseif(ansPlay == 'Y' || ansPlay == 'y')
{
cout<<"Wonderful! Let's Play!";
break;
}
else
{
cout<<"The answer needs to be <Y>es or <N>o. Try again."<<endl;
}
}
cin.get();
return 0;
}
Now, when I give "yes" or "no" or anything starting with an "n" or a "y" it works just fine. But if I enter for example: "asdf", it gives the output: "The answer needs to be <Y>es or <N>o. Try again." four times, once for every character. So I was wondering if there's a way to discard all characters that come after the first? Or if this is not the right way to do it, how should it be done?
Thanks in advance.