+ 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"; } }
2 Answers
+ 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
0
G'day Ceratos sometimes you've just gotta try it. Give it a go & see if it works?