do-while loop that make me sick


do{
cout<<"\n\n\n P-Print Receipt S-Save to File\n";
cin>>pos;

if (pos=='P' || pos=='p')
{
cout<<" Loading...\n";
timer();
cout<<" No Printer is connected. Record has been save to file.\n\n";
}
else if (pos=='s' || pos=='S')
{
cout<<" Invoiced saved!\n";
}
else
{
cout<<" Error Input! Refer to the Choices!";
timer ();
system ("cls");
}
}while (pos!='s' || pos!='S' || pos!='P' || pos!='p');


i keep on staring at this code,, whatever i input it keeps on looping. try to stare at it guys, you might see whats wrong.
This is a common mistake that have been explained before.
http://www.cplusplus.com/forum/beginner/62804/
Change

while (pos!='s' || pos!='S' || pos!='P' || pos!='p')

to

while (pos!='s' && pos!='S' && pos!='P' && pos!='p')

In fact you could write

while ( ! ( pos == 's' || pos =='S' || pos =='P' || pos =='p' ) )

If to remove negation '!' then we get

while ( pos!='s' && pos!='S' && pos!='P' && pos!='p')
thanks guys...
thanks
Last edited on
Topic archived. No new replies allowed.