我正在为我的学生制作评分应用程序,但我的比较运算符没有按照我期望的方式运行。我的代码如下;
float FINAL = ((_gradeyouwant - (_quarter1 * 0.2f) - (_quarter2 * 0.2f) - (_quarter3 * 0.2f) - (_quarter4 * 0.2f) - (_quarterM * 0.1f)) / 0.1f);
NSLog(@"q1 = %.2f", _quarter1);
NSLog(@"q2 = %.2f", _quarter2);
NSLog(@"q3 = %.2f", _quarter3);
NSLog(@"q4 = %.2f", _quarter4);
NSLog(@"qM = %.2f", _quarterM);
NSLog(@"qF = %.2f", FINAL);
NSLog(@"grade = %.2f", _gradeyouwant);
if ((FINAL > 4.3f))
{
[_result setText:[NSString stringWithFormat:@"It is not possible to get your desired grade."]];
}else if ((FINAL > 4.0f))
{
[_result setText:[NSString stringWithFormat:@"You would need to get an A+"]];
}else if ((FINAL > 3.7f))
{
[_result setText:[NSString stringWithFormat:@"You would need to get an A"]];
}else if ((FINAL > 3.3f))
ETC. ETC.
当您使用 NSLog 查看输出时,它会告诉我所有内容的正确值。但是,如果我让它最终是 4.0,它不会打印正确的字符串。我在想当它到达 FINAL > 4.0 时,它不会运行那条线。但确实如此。我究竟做错了什么?提前非常感谢!