views:

49

answers:

1

I am trying to figure out how to create an 'if' statement that uses a time value as a condition. For example:

if (time <= 10:00) {
    score = 3;
} else if (time <= 20:00) {
    score = 5;
} else {
            score = 9;
}   

I know that a string of "5:23" cannot be compared this way but I don't think I can just turn a string value like that directly into an integer. Any thoughts?

+1  A: 

Try this:

NSString *realTimeString = @"10:00";
NSString *someTimeString = [realTimeString stringByReplacingOccurrencesOfString:@":"
                                           withString:@"."];
float time = [someTimeString floatValue];

if (time <= 10.00) {
    score = 3;
} else if (time <= 20.00) {
    score = 5;
} else {
    score = 9;
}
Jacob Relkin