while loop

Why does the following code keep displaying
"Please enter either A,B,C D,or F even when I do enter one of those letters?

cout<<"Please enter Letter grade for course 1 using capital Letters"<<endl;
cin>>grade1;

while ((grade1 != 'A') || (grade1 != 'B')|| (grade1 != 'C')||(grade1 != 'D')||(grade1 != 'F'))
{cout<<"Please Enter Either A, B, C, D, or F.";
cin>>grade1;}
You're checking whether any single one of those conditions is not true, which is always going to be the case. Try either of these...

while (!(grade1 == 'A' || grade1 == 'B' || grade1 == 'C' || grade1 == 'D' || grade1 == 'F'))

while (grade1 != 'A' && grade1 != 'B' && grade1 != 'C' && grade1 != 'D' && grade1 != 'F')

DeMorgan's laws are helpful to figure these statements out.
http://en.wikipedia.org/wiki/De_Morgan's_laws
The logic makes Sense!
Thank you!
Topic archived. No new replies allowed.