我正在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