Calculation Conundrum - how do I influence another textfield?

Posted by LawVS on Stack Overflow See other posts from Stack Overflow or by LawVS
Published on 2010-03-08T13:34:22Z Indexed on 2010/03/08 13:36 UTC
Read the original article Hit count: 357

Filed under:
|
|
|
|

Hey!

Basically I have a problem in that when certain parameters are used in my calculator app - it makes the result incorrect. The issue is that I have separate text fields for hours and minutes and say for example I have as the start time "13" in one text field and "30" in the other with the finish time "24" and "00" in their respective text fields. The answer should be 10 hours 30 minutes, but the answer I get is 11 hours 30 minutes. The code for this is the following.

 -(IBAction)done:(id)sender {
  int result = [finishHours.text intValue] - [startHours.text intValue];
  totalHours.text = [NSString stringWithFormat:@"%d", result];
  if (result < 0) { 
    totalHours.text = [NSString stringWithFormat:@"%d", result + 24];
  }



    -(IBAction)done2:(id)sender {
  int result = [startMinutes.text intValue] - [finishMinutes.text intValue];
  totalMinutes.text = [NSString stringWithFormat:@"%d", result];
  if (result < 0) {
    totalMinutes.text = [NSString stringWithFormat:@"%d", result + 60];
  }
}

I want to make it so if certain parameters are met, then the totalHours.text is reduced by 1 hour to reflect the total minutes. How would I go about that calculation in code?

Thanks!

© Stack Overflow or respective owner

Related posts about calculation

Related posts about time