iPhone producing strange results on 'if' statement

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-06-14T16:05:40Z Indexed on 2010/06/14 16:32 UTC
Read the original article Hit count: 176

Filed under:
|

I have a UIPicker where the user inputs a specified time (i.e. 13:00, 13:01, 13:02, etc.) - which determines their score. Once they hit the button an alert comes up with the score that is determined through this 'if-else' statement. Everything seems to work great MOST of the time - but I am getting some erratic behavior. This is the code:

    //Gets my value from the UIPicker and then converts it into a format that can be used in the 'if' statement.    
    NSInteger runRow = [runTimePicker selectedRowInComponent:2];
    NSString *runSelected = [runTimePickerData objectAtIndex:runRow];
    NSString *runSelectedFixed = [runSelected stringByReplacingOccurrencesOfString:@":" withString:@"."];

    //The actual 'if' statment.
    if ([runSelectedFixed floatValue] <= 13.00) {
    runScore = 100;
} else if ([runSelectedFixed floatValue] <= 13.06) {
    runScore = 99;
} else if ([runSelectedFixed floatValue] <= 13.12) {
    runScore = 97;
} else if ([runSelectedFixed floatValue] <= 13.18) {
    runScore = 96;
} else if ([runSelectedFixed floatValue] <= 13.24) {
    runScore = 94;
} else if ([runSelectedFixed floatValue] <= 13.30) {
    runScore = 93;
} else if ([runSelectedFixed floatValue] <= 13.36) {
    runScore = 92;
} else if ([runSelectedFixed floatValue] <= 13.42) {
    runScore = 90;
} else if ([runSelectedFixed floatValue] <= 13.48) {
    runScore = 89;
} else if ([runSelectedFixed floatValue] <= 13.54) {
    runScore = 88;
}

Now, when I test the program, I will get the expected result when I choose '13:00' which is '100'. I also get the expected result of '99' when I choose all of the times between '13:01 and 13:05'. BUT, when I choose '13:06' it gives me a score of '97'. I also get a score of '97' on '13:07 through 13:12' - which is the desired result. Why would I get a '97' right on '13:12' but not get a '99' right on '13:06'???? Could this be a memory leak or something???

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c