is there anyway i can enum a number range ?
eg
instead of enum { black=1, white =2}
i want black to have a range 1~10 ?
i tried enum{black=1-10) , it compiles , but doesn't work
is there anyway i can enum a number range ?
eg
instead of enum { black=1, white =2}
i want black to have a range 1~10 ?
i tried enum{black=1-10) , it compiles , but doesn't work
It does work. Just not the way you want. It equates to: "black = -9".Originally posted by Unregistered
is there anyway i can enum a number range ?
eg
instead of enum { black=1, white =2}
i want black to have a range 1~10 ?
i tried enum{black=1-10) , it compiles , but doesn't work
No, there is no way to use ranges. You cannot do this with case statements or enums. Your best bet is:
enum { black=1, white=11, red=21 ... };
if( color < white ) printf("black"); else
if( color < red ) printf("white"); else
if( ... ) ...
Quzah.
Hope is the first step on the road to disappointment.
I wrote this to help explain/expand the answer, but I see quzah has already done something similar. Here it is anyway:
Code:#include <stdio.h> enum Sizes {MICROSCOPIC, TINY, SMALL, MEDIUM, BIG, EVENBIGGER, BLOODYHUGE}; int main(void) { enum Sizes MySize = BIG; printf ("My Size is %d\n", MySize); if (MySize > MEDIUM) printf ("That's big enough!\n"); else printf ("That's too small!\n"); return 0; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]