do while loop simple question

char ans;
do
{
cout<< "Do you want to continue (Y/N)?\n";
cout<< "You must type a 'Y' or an 'N'.\n";
cin >> ans;
}
while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n'));

What is the meaning of (ans !='Y'), my concept is when the ans is Y so it is false because "!=" this operator means not equal ...
Yes, your understanding is correct. The loop will continue if the user types Y, y, N, or n, but if they type anything else it will end. That's probably not what was wanted, however.
Last edited on
Topic archived. No new replies allowed.