How can I check that the user actually is inputting what I want them to?
(For example letters or numbers);
I need the user to input y or n, so here is how i tried to solve it:
char answer;
do
{
system("cls");
cout <<"Want to play? <y/n>: ";
cin>>answer;
}while(tolower(answer)!='y' && tolower(answer) != 'n');
while(answer=='y')
{
//some game or whatever
cout <<"weee, again?";
cin>>answer; //again?
}
Any good?
Seems to me like I would have to do a while loop for every input so I know they're not inputting something else than what I want (letters/numvers/etc)
Isn't there a better way? There has to be...?
Also, with this code, if I just press enter it will go to the next line can I fix that?
It doesn't count it as an input - I think - it just jumps to the next line...