BMI(Body mass index)は体格を示す指数であり、肥満の判定と肥満症の診断についての基準を示している。男女ともBMIが22の時に高血圧、高脂血症、肝障害、耐糖能障害等の有病率が最も低くなるという。あなたの身長と体重を入力し、BMIを計算し、判定結果として表のようなメッセージを表示するプログラムを作成せよ。
BMI=体重(kg)÷身長(m)^2
入力例:
Enter your height and wieght : 172 61
Your BMI:20.6
Your obesity is Normal
BMI=体重(kg)÷身長(m)^2
BMI | 分類 | Classification |
18.5未満 | 低体重 | Underweight |
18.5以上25.0未満 | 普通体重 | Normal |
25.0以上29.9未満 | 肥満1度 | Overweight |
30.0以上34.9未満 | 肥満2度 | Obese class I |
35.0以上39.9未満 | 肥満3度 | Obese class II |
40.0以上 | 肥満4度 | Obese class III |
#include<iostream> using namespace std; int main(){ int a, b; double c, h; cout << "Enter your height(cm) and weight(kg) : "; cin >> a >> b; h = double (a)/100; c = b/(h*h); // c = b / pow(h,2); cout << "Your BMI" << setqrecision(3) << c << "\n"; if (c<18.5) cout << "Underweight" << "\n"; else if (c<25.0) cout << "normal" << "\n"; else if (c<30.0) cout << "Overweight" << "\n"; else if (c<35.5) cout << "Obese class I" << "\n"; else if (c<40.0) cout << "Obese class II" << "\n"; else cout << "Obese class 3" << "\n"; return 0; }
入力例:
Enter your height and wieght : 172 61
Your BMI:20.6
Your obesity is Normal
このページへのコメント
XDel7q Major thankies for the blog post.Much thanks again. Much obliged.
RfU3mG Appreciate you sharing, great post.Thanks Again. Much obliged.
コピーペーストで実行してみたのですが、うまく作動しません。確認よろしくお願いします。