# C++ 學習 ###### tags: `BMI練習` ``` #include <iostream> using namespace std; int main() { char gender; float height,weight; float hf; float BMI; cin>>gender; cin>>height; cin>>weight; // cout << gender << "\n"; // cout << height << "\n"; // cout << weight << "\n"; //方法1 // hf = height/100; // BMI = weight/(hf*hf); //方法2 BMI = (weight/(height*height))*10000; // cout << hf << "\n"; cout << BMI << "\n"; if(gender == 'm'){ if(BMI < 18){ cout << "體重過輕" << "\n"; }else if(BMI >= 18 && BMI < 24){ cout << "體重標準" << "\n"; }else if(BMI >= 24 && BMI < 27){ cout << "體重過重" << "\n"; }else if(BMI >= 27 && BMI < 30){ cout << "輕度肥胖" << "\n"; }else if(BMI >= 30 && BMI < 35){ cout << "中度肥胖" << "\n"; }else if(BMI >= 35){ cout << "重度肥胖" << "\n"; } }else{ if(BMI < 18){ cout << "體重過輕" << "\n"; }else if(BMI >= 18 && BMI < 24){ cout << "體重標準" << "\n"; }else if(BMI >= 24 && BMI < 27){ cout << "體重過重" << "\n"; }else if(BMI >= 27 && BMI < 30){ cout << "輕度肥胖" << "\n"; }else if(BMI >= 30 && BMI < 35){ cout << "中度肥胖" << "\n"; }else if(BMI >= 35){ cout << "重度肥胖" << "\n"; } } return 0; } ``` [c++ 線上編輯器](https://ideone.com/) ``` //stdin m 172 68 //stdout 22.9854 體重標準 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up