Hi, I'm looking for an equivalent for a < or > in a switch statement.
IE:
switch (number){
case 10 <number< 20: blah;
break;
case number >20: bleh;
break;
default: bleg;
break;
}
anyone know how to do this?
Hi, I'm looking for an equivalent for a < or > in a switch statement.
IE:
switch (number){
case 10 <number< 20: blah;
break;
case number >20: bleh;
break;
default: bleg;
break;
}
anyone know how to do this?
You can use if/else statements. Like the code just put here.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I know this, but I would have sworn that there was a work around. (that I have compeletely forgotten)
I really don't want to start changing all my code around =/
i tried searching too... didn't help because I couldn't think of any great key words that would find the answer
Thats about the best you can do with a switch for this sort of thing. You would probably be better using a different structure. If/else can be useful but be careful not to get elseifheimers disease.Code:switch (num) { case 1: case 2: case 3: case 4: { cout <<"Less than five";break;} case 5: case 6: case 7: case 8: case 9: { cout<<"Less than ten";break;} default: cout<<"Not single digit num"; }
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
figured, just thought I'd ask....
thnx all