Can anyone see if there’s problem with the way i handle the calculation below? I seemed to be getting “You scored 0” at runtime even when the answer is actually correct.
- (void)countGain{
int gain = 0;
int percentage;
if ([answer objectForKey:@"1"] == [usrAnswer objectForKey:@"1"]) {
gain += 1;
}
percentage = (gain / 10) * 100;
NSString *scored = [[NSString alloc] initWithFormat:@"You scored %d",percentage];
score.text = scored;
rangenans.text = [answer objectForKey:@"1"];
[scored release];
}
What is the point doing:
Use
Rest looks good. You shouldn’t divide integers. What if you get 3/10 and this is int value?
In condition change
To: