input validation

hey, i want to make a yes or no question,
if (yn=='Y' || yn=='y')
goto sem;
else if (yn=='N' || yn=='n')
{
cout<<"Thanks" <<endl;
}
else if(yn!= 'y' || 'n' || 'Y' || 'N')
{
cout <<"only (y/n) are allowed" <<endl;
goto ask;
}
else
{cout<<"false"<<endl;}

that's my code,
but my problem is when i input "yes" or any words that start with y, the program think it as 'y'
any idea to solve this problem??
thank for any suggest
Last edited on
Try:
else if(yn!== 'y' || yn!== 'n' || yn!=='Y' || yn!== 'N')
Also i'm not sure on this as I don't program this way (sorry) but i think when your checking for a single letter all it does is read the first letter of what word you enterd. That i'm not exactly sure how to fix sadly enough haha. I'm sure i've done it a while ago but can't think of it off the top of my head. Don't worry though someone here is sure to know :)
thaks alot... i'll try this one hehe
Sorry I couldn't be of more help. Post back how it goes :)
get the response on a string then check it only if it has just one character
Ah very nice - i know what you mean. Now i feel stupid for not thinking of that aha
If your working with a char. You can do:

else if ( (toupper(yn) != 'Y') && (toupper(yn) != 'N') )

If it's not a char, but a string.
else if ( (yn != "y") && (yn != "Y") && (yn != "n") && (yn != "N") )
Nice and neatly said
thanks for your suggest..
anyway i finish it using .lenght hehehe
thanks for all your help..
Topic archived. No new replies allowed.