I recently coded a simple BMI calculator in C++ to practice what I'm learning.
The program asks for weight in kg and height in meters. It squares the height and calculates the BMI by dividing weight by height squared. Then using if-else statements, it prints if your weight is proportional to your height along with a short piece of advice.
include
using std::cout;
using std::cin;
using std::endl;
int main()
{ char next_;
do {
double weight,height,BMI;
cout << "enter your weight :" << endl;
cin >> weight;
cout << "enter your height :" << endl;
cin >> height;
cout << "\n=========================" << endl;
cout << "your weight is " <<weight<<" Kg\n"<< endl;
cout << "your height is " << height<<" m\n"<< endl;
cout << "\n=========================" << endl;
BMI=weight/(height*height);
if (BMI<18.5)
cout << "You are Underweight !\n Requires healthy nutritional increase." << endl;
else if(BMI<=24.9 && BMI>=18.5)
cout << "Good! your weight is Normal .\nMaintain current diet and healthy lifestyle ." << endl;
else if (BMI>=25.0 && BMI<=29.9)
cout << "Overweight !\nNeeds calorie reduction and increased activity ." << endl;
else if (BMI>=30.0 && BMI<=34.9)
cout << "Obesity (Class I) .\n Requires a weight loss diet plan ." << endl;
else if (BMI >=35.0 && BMI<=39.9)
cout << "Obesity (Class II) .\nRequires consultation with a nutritionist ." << endl;
else
cout << "Sorry ! \n Severe Obesity (Class III) .\nRequires intensive medical intervention ." << endl;
cout << "\n\nIf you want to stop press t, otherwise press any key. " << endl;
cin >> next_;
} while (next_!='t' && next_!='T');
return 0;
}
Feel free to leave a note or comment to help me learn and improve!
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.