How to have an if() split by && and not ||

  • A+
Category:Languages

I'm trying to do something like this in c++

If x is equal to either a or b or c and y is equal to either d or e or f and z is equal to either g or h or i, it would turn true and execute the code 

I am a bit lost in this

if(x==a||x==b||x==c && y==d||y==e||y==f && z==g||z==h||z==i){  // Do x } 

 


Just use && and ||, with parentheses to make the grouping clear.

if ((x == 'a' || x == 'b' || x == 'c')      && (y == 'd' || y == 'e' || y == 'f')     && (z == 'g' || z == 'h' || z == 'i')) {     // execute code } 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: