Hi all,
This code block is making sure the user is entering the correct character, either y/n.
char response;
cout<<"\nDo you want to continue? (y/n): ";
cin>>response;
cout<<endl;
while(response != 'y' || response != 'n')
{
if (response == 'y' || response == 'n')
break;
cout<<response<<" is an invalid input. Please re-enter your answer (y/n): ";
cin>>response;
}
as you guys can see, an "if...block" doesn't need to be there, but if I remove it, my program will keep asking user to enter valid repsonse character, another words, it's infinity loop. I tested this on VS 1005 express edition and Unix. they are both produced the same result.
if anyone have an idea/something wrong/better way to accomplish this task with this code block, I am greatly appreciated it.
Henry