我有一些Objective C,但我不理解变量比较运算符:
if ([bmiView.text floatValue] < 18.50) {
classification.text = @"Underweight";
bmiImageView.image = [UIImage imageNamed:@"underweight.png"];
}
if ([bmiView.text floatValue] > 18.50 < 24.99) {
classification.text = @"Healthy";
bmiImageView.image = [UIImage imageNamed:@"healthy.png"];
}
if ([bmiView.text floatValue] > 25 < 29.99) {
classification.text = @"Overweight";
bmiImageView.image = [UIImage imageNamed:@"overweight.png"];
}
if ([bmiView.text floatValue] > 30 < 39.99) {
classification.text = @"Obese";
bmiImageView.image = [UIImage imageNamed:@"obese.png"];
}
if ([bmiView.text floatValue] > 40) {
classification.text = @"Very Obese";
bmiImageView.image = [UIImage imageNamed:@"veryobese.png"];
}
每次我运行应用程序时,当用户的 BMI 超过 40.00 时,唯一正常工作的分类是“非常肥胖”。任何其他 BMI 都会导致以下分类,即“肥胖”,这应该适用于 30.00 到 39.99 之间的 BMI。为什么它不起作用?