私は友人が体重を減らすのを助けることに決めました。私はコーディングを知っていて、あなたのBMI(体質指数)を計算するプログラムを開発しようとしています。 ifステートメント。彼らは私がそれらを期待する方法を働いていない。ここに私がこれまでに持っていることがあり、それを見て、それがなぜ機能していないのか理解できません。私のifステートメントのデバッグ
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double weight;
double height;
double bmi;
cout << "Enter weight in kilograms:\n";
cin >> weight;
cout << "Enter height in metres:\n";
cin >> height;
bmi = weight/(pow(height,2));
if (bmi < 18.5) {
cout <<"Your BMI is " << bmi <<", which means you are in the Underweight range" << endl;
}
else {
(bmi > 18.5) && (bmi < 24.9)
cout <<"Your BMI is " << bmi <<", which means you are in the Normal range" << endl;
}
else {
(bmi > 25.0) && (bmi < 29.9)
cout <<"Your BMI is " << bmi <<", which means you are in the Normal range" << endl;
}
else (bmi > 30) {
cout <<"Your BMI is " << bmi <<", which means you are in the Obese range" << endl;
}
return 0;
}
私は他に何度も使用できると言われましたが、それがエラーの原因かもしれないと私は考えています。
ありがとうございます。
構文が間違っています:if(cond){if} else if(cond2){... } else if(cond3){...} else {....} ' – Garf365
@ Garf365素晴らしいおかげで、私はそれを今すぐ行けます! –
なぜ2つの「正常範囲」がありますか?違いは何ですか?他のものよりもう一つは「普通」ですか? –