+ 3

C++ comparison/boolean-logic

How to compare multiple variables with a number? For example: Is there something like this if ( (a,b,c,d,e)>10 ) instead of if ( a>10 || b>10 || c>10 || d>10 || e>10 )

17th May 2019, 10:15 PM
Илья Карпенко UA
Илья Карпенко UA - avatar
2 ответов
+ 6
Don't know if it makes it easier in your case, but maybe loop over the values? int a=5, b=7, c=11, d=17, e=3; for(int n: {a, b, c, d, e}) if (n>10) cout << n << endl;
17th May 2019, 10:45 PM
HonFu
HonFu - avatar
+ 2
You can use a for loop on a fixed dimension array and return the resulting output in another array🤔
18th May 2019, 12:16 PM
Sanjay Kamath
Sanjay Kamath - avatar