冰楓論壇

標題: 我練習寫一個BMI程式 [打印本頁]

作者: x傳奇x    時間: 2015-10-19 16:01
標題: 我練習寫一個BMI程式
如標題~
但我寫完之後數字都對,身體質量指數(BMI)卻只有在過輕跟正常才會對
後面的過重都會顯示正常,有那位大大可以幫我解答一下嗎
附程式碼:
#include <iostream>
using namespace std;
int main()
{
        double weight, height, BMI;
        cout << "本程式計算BMI值,並提供身體質量資訊" << endl;
        cout << "請輸入身高(1~300公分):";
        cin >> height;
        cout << "請輸入體重(1~400公斤):";
        cin >> weight;
        BMI = weight / (height/100.0*height/100.0);
        cout << "BMI值為:" << BMI;
        if (BMI<18.5)
                cout << " 體重過輕" << endl;
        else if (18.5<=BMI<24.0)
                cout << " 正常範圍" << endl;
        else if (24.0<=BMI<27.0)
                cout << " 過重" << endl;
        else if(27.0 <= BMI<30.0)
                cout << " 輕度肥胖" << endl;
        else if(30.0 <= BMI<35.0)
                cout << " 中度肥胖" << endl;
        else
                cout << " 重度肥胖" << endl;
        system("pause");
        return 0;
}
作者: 匿名    時間: 2022-10-11 09:51
#include <iostream>
using namespace std;

int main()
{
    float a,b,bmi;
    cin>>a>>b;
    bmi=b/(a/100.0*a/100.0);
    //cout<<bmi;
    if(bmi<18){
        cout<<"underweight";
    }
    else if((18<=bmi)&&(bmi<24)){
        cout<<"normal";
    }
    else if(bmi>=24){
        cout<<"overweight";
    }
    else{
        cout<<"error";
    }
   
    return 0;
}




歡迎光臨 冰楓論壇 (https://bingfong.com/) Powered by 冰楓