I am trying to get the rate per minute that someone is pushing a button on iOS.When they press the button, a label is updated with the presses per minute. I have the code mostly working, but it is spitting out large positive/large negative numbers for the rate. I think it is in my math for computing the average. Any help would be appreciated and if you need any more information please let me know!
- (IBAction)countStroke:(id)sender {
double avg;
double start = [[NSDate date] timeIntervalSince1970];
if(start - endStroke > 60){
count = 0;
}
if(count == 0){
NSString *firststroke = [[NSString alloc] initWithFormat:@"First Stroke"];
self.label.text = firststroke;
endStroke = [[NSDate date] timeIntervalSince1970];
count ++;
}
else {
endStroke = [[NSDate date] timeIntervalSince1970];
avg = ((60000 * count)/(endStroke - start));
NSString *rate = [NSString stringWithFormat:@"%d", avg];
self.label.text = rate;
}
}
%dis used for integer values. Use%finstead