我正在C中进行一项任务,在C中我必须阅读多个人的身高和体重并确定他们的bmi。然后,我把它们归类到各自的BMI类别,但我被陷在如何做到这一点正确的,这是我的代码至今:BMI分类结构
# include <stdio.h>
int main() {
int people;
double bmi, weight, inches;
printf("How many peoples? > ");
scanf("%d", &people);
do {
printf("Enter height (inches) and weight (lbs) (%d left) > ", people);
scanf("%lf %lf", &inches, &weight);
people--;
}
while (people > 0);
bmi = (weight/(inches * inches)) * 703;
if (bmi < 18.5) {
printf("Under weight: %d\n", people);
}
else if (bmi >= 18.5 && bmi < 25) {
printf("Normal weight: %d\n", people);
}
else if (bmi >= 25 && bmi < 30) {
printf("Over weight: %d\n", people);
}
else if (bmi >= 30) {
printf("Obese: %d\n", people);
}
return 0;
}
我在哪里去了?我在哪里修复此代码?
你是否建议分配另一个变量来表示“people--”,比如y = people--;? – Student 2013-04-26 10:18:47
请参阅我更新的代码,并尝试按照您的风格进行操作。 – Jeyaram 2013-04-26 10:23:35
谢谢!即时通讯将使用你所做的,并重新编写我的代码,所以我可以肯定,我完全理解它 – Student 2013-04-26 10:32:39