这是一种简单的Objective-c方法来计算得分。即使它不应该这样做,我得到所有4分的F的结果。我做错了什么?
-(void) updateLetters:(int)score andLabel:(UILabel*)labelName {
if(score>=97)
labelName.text= @"A+";
else if(score>=94)
labelName.text= @"A";
else if(score>=90)
labelName.text= @"A-";
else if(score>=87)
labelName.text= @"B+";
else if(score>=84)
labelName.text= @"B";
else if(score>=80)
labelName.text= @"B-";
else if(score>=77)
labelName.text= @"C+";
else if(score>=74)
labelName.text= @"C";
else if(score>=70)
labelName.text= @"C-";
else if(score>=67)
labelName.text= @"D+";
else if(score>=64)
labelName.text= @"D";
else if(score>=60)
labelName.text= @"D-";
else labelName.text=@"F";
}
- (void)viewDidLoad {
[super viewDidLoad];
int r1score=appDelegate.correctAnswersCountR1;
int r2score=appDelegate.correctAnswersCountR2;
int r3score=appDelegate.correctAnswersCountR3;
int r4score=appDelegate.correctAnswersCountR4;
r1score=(r1score/17)*100;
r2score=(r2score/17)*100;
r3score=(r3score/17)*100;
r4score=(r4score/17)*100;
[self updateLetters: r1score andLabel: R1];
[self updateLetters: r2score andLabel: R2];
[self updateLetters: r3score andLabel: R3];
[self updateLetters: r4score andLabel: R4];
}
答案 0 :(得分:4)
(R1score / 17)* 100总是会得到0,因为它都是整数数学。
尝试(得分/ 17.0)* 100.0