tags:

views:

92

answers:

2
NSString *r1=[r11 text];
NSInteger intR1=[r1 intValue];

ig=ig+(200-intR1);

I have a situation here where I need the following calculation to happen if [r11 text] will give the following output for example...

  • 1:55...I want the calculation to be (2:00-1:55) = 5
  • 2:03...I want the calculation to be (2:00-2:03) = -3
  • 1:49...I want the calculation to be (2:00-1:49) = -11

These are examples above. Basically "2:00" is the 0 point is what I am looking for.

These calcualtions are dealing with times so 2:00 is 2 min 1:55 is 1min 55sec. but I need to make the calculation off of integers.

A: 

I don't speak objective c, but the general idea would be

-assuming always the last 2 numbers are seconds, anything before is minutes:

int minutes = ig / 100; //(should floor);
int seconds = ig - (minutes * 100);

int totalSeconds = minutes*60 + seconds;

ig = ig + 120 - totalSeconds;
Ben Schwehn
For this senario since `200` is supposed to be 2 minutes the last line would need to be `ig = ig + 120 - totalSeconds;`.
theMikeSwan
@theMikeSwan: I guess you're right, thanks. Not entirely sure if my answer really is what the OP ist looking for though tbh...
Ben Schwehn
A: 

Currently in your last step you are taking the value that is currently in ig and adding it to the result of your desired formula. You are also taking extra steps that you don't need to do. If you just want an int that is the result of 200 minus the value of r11 then try this. int ig = 200 - [r11 intValue];. You should be able to adjust that as you need to fit your specific needs.

theMikeSwan