Connecting Tech Pros Worldwide Forums | Help | Site Map

Little help with this if statement

Newbie
 
Join Date: Mar 2008
Posts: 9
#1: Mar 26 '08
I trying to make it so letter1 and letter2 must be c, C,q or Q, but this code is not working because basically when I have a c, its not a q or a Q so the if statement would take into place. What code would I put in that would check for all 4 instances?

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (letter1 != 'c' || letter1 != 'C' || letter1 != 'q' || letter1 != 'Q')
  3.     {
  4.         cout << "AYE" <<endl;
  5.         x = 0 ;
  6.         x = 0; 
  7.     }
  8.     if (letter2 != 'c' || letter2 != 'C' || letter2 != 'q' || time_period2 != 'Q' )
  9.     {
  10.         cout << "AYE" <<endl;
  11.         x = 0
  12.         y = 0; 
  13.     }
  14.  
-Jeff

Expert
 
Join Date: Sep 2007
Posts: 856
#2: Mar 26 '08

re: Little help with this if statement


You've got the wrong logical operator. You don't want it to be OR, since that returns true if one of the statements is true. You only want it to return true if both are true. What logical operator is that?
Reply