c++ - How to write multiple if conditions -



c++ - How to write multiple if conditions -

i have 2 variables a , b , want write code if 1 of 2 variables equal

151 or 156 or 720

and other not equal 1 of these numbers 3rd variable c = 0 equal one.

so illustration

1) if = 151 , b = 700 c = 1 2) if = 151 , b = 720 c = 0 3) if = 140 , b = 700 c = 0

this code

int = 0 cin >> a; int b = 0 cin >> b; int c=0; int decklist[3] = {151,156,720} for(int d=0; d<3;d++){ if(a== decklist[d]){ for(int w=0; w<3;w++){ if(b==decklist[w]) c=0; else c=1; } } if(b== decklist[d]){ for(int w=0; w<3;w++){ if(a==decklist[w]) c=0; else c=1; } } }

is ok? there other improve ways of doing it?

this exclusive or, xor. there no logical xor in c++, can utilize bit-wise xor case , exploit fact result of logical operator bool map 0 or 1:

#include <iostream> int main() { int a, b, c; std::cin >> a; std::cin >> b; = (a == 151 || == 156 || == 720); b = (b == 151 || b == 156 || b == 720); c = ^ b; std::cout << c << std::endl; }

i've used simple look here check whether number 1 of 3 supplied numbers. larger sets of numbers check against, utilize a, well, std::set.

c++

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -