+ 1

Comparison in switch

I want to go through the simulator using the switch operator, but I can't understand whether the comparison can be fully used in the case or only if it is equal. For example: int x; cin << x; // Sorry, I don 't have a tab switch (x) { case (x>0): { cout << "greater than 0"; break } register (x<0): { cout << "less than 0" break } default value { cout << "0"; } }

26th Mar 2022, 3:24 AM
Ceratos
Ceratos - avatar
2 ответов
+ 1
The comparison can be fully used only if it met the conditions. Example if its x > 1 means the condition is valid when x is 2, 3, 4 .... not 1 or less than 1
26th Mar 2022, 6:07 AM
ShadowCipher
ShadowCipher - avatar
0
G'day Ceratos sometimes you've just gotta try it. Give it a go & see if it works?
26th Mar 2022, 6:10 AM
HungryTradie
HungryTradie - avatar