Hi,
I wrote the following function using if statements.
Everything works fine except for two bugs. If ct is equal to .04, .08, 0.7, or 0.9 the function returns the value in the previous return statement. So for example, when ct is .04 it returns 0 and not 1. The same weird behavior occurs with the numbers I specified above, but works well with all the other numbers. Any suggestions?
Thanks.
- (int) sizeIndexfloat) ct
{
NSLog(@"%f", ct);
if (ct > 0 && ct < 0.04) return 0;
if (ct >= 0.04 && ct < .08) return 1;
if (ct >= 0.08 && ct < .15) return 2;
if (ct >= 0.15 && ct < .18) return 3;
if (ct >= 0.18 && ct < .23) return 4;
if (ct >= 0.23 && ct < .3) return 5;
if (ct >= 0.3 && ct < .4) return 6;
if (ct >= 0.4 && ct < .5) return 7;
if (ct >= 0.5 && ct < .7) return 8;
if (ct >= 0.7 && ct < .9) return 9;
if (ct >= 0.9 && ct < 1) return 10;
if (ct >= 1 && ct < 1.5) return 11;
if (ct >= 1.5 && ct < 2) return 12;
if (ct >= 2 && ct < 3) return 13;
if (ct >= 3 && ct < 4) return 14;
if (ct >= 4 && ct < 5) return 15;
if (ct >= 5 && ct < 10) return 16;
if (ct >= 10) return 17;
else return -1;
}
I wrote the following function using if statements.
Everything works fine except for two bugs. If ct is equal to .04, .08, 0.7, or 0.9 the function returns the value in the previous return statement. So for example, when ct is .04 it returns 0 and not 1. The same weird behavior occurs with the numbers I specified above, but works well with all the other numbers. Any suggestions?
Thanks.
- (int) sizeIndexfloat) ct
{
NSLog(@"%f", ct);
if (ct > 0 && ct < 0.04) return 0;
if (ct >= 0.04 && ct < .08) return 1;
if (ct >= 0.08 && ct < .15) return 2;
if (ct >= 0.15 && ct < .18) return 3;
if (ct >= 0.18 && ct < .23) return 4;
if (ct >= 0.23 && ct < .3) return 5;
if (ct >= 0.3 && ct < .4) return 6;
if (ct >= 0.4 && ct < .5) return 7;
if (ct >= 0.5 && ct < .7) return 8;
if (ct >= 0.7 && ct < .9) return 9;
if (ct >= 0.9 && ct < 1) return 10;
if (ct >= 1 && ct < 1.5) return 11;
if (ct >= 1.5 && ct < 2) return 12;
if (ct >= 2 && ct < 3) return 13;
if (ct >= 3 && ct < 4) return 14;
if (ct >= 4 && ct < 5) return 15;
if (ct >= 5 && ct < 10) return 16;
if (ct >= 10) return 17;
else return -1;
}