授業中に作成したプログラムを片っ端から乗っけていきです。C++ を中心に掲載中。

BMI(Body mass index)は体格を示す指数であり、肥満の判定と肥満症の診断についての基準を示している。男女ともBMIが22の時に高血圧、高脂血症、肝障害、耐糖能障害等の有病率が最も低くなるという。あなたの身長と体重を入力し、BMIを計算し、判定結果として表のようなメッセージを表示するプログラムを作成せよ。
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.

0
Posted by awesome things! 2014年01月22日(水) 08:15:34 返信

RfU3mG Appreciate you sharing, great post.Thanks Again. Much obliged.

0
Posted by seo thing 2013年12月19日(木) 17:28:21 返信

コピーペーストで実行してみたのですが、うまく作動しません。確認よろしくお願いします。

0
Posted by dex 2009年10月29日(木) 18:07:50 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Creative Commons

Creative Commons License
この作品は、クリエイティブ・コモンズ・ライセンスの下でライセンスされています。

メンバーのみ編集できます