C++ Selestion: Body Mass Index: Write a program that calculates and displays a p
ID: 3794207 • Letter: C
Question
C++ Selestion: Body Mass Index: Write a program that calculates and displays a person’s body mass index (BMI) when the user provides their weight and height. The BMI is often used to determine whether a person is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula:
BMI = (weight in lbs * 703)/ (height in inches)2
Where weight is measured in pounds and height is measured in inches. The program should display a message indicating whether the person has optimal weight (BMI between 18.5 and 25 inclusive), is underweight (BMI less than 18.5), or is overweight (BMI greater than 25). The program should also display the calculated BMI.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
double feet;
double inches;
double height;
double weight;
double bmi;
cout<<"== BMI Calculator =="<<endl;
cout<<"Step 1: Enter height"<<endl;
cout<<"Feet:"<<endl;
cin>>feet;
cout<<"Inches:"<<endl;
cin>>inches;
cout<<"step 2: Enter weight"<<endl;
cout<<"Pounds:"<<endl;
cin>>weight;
height = (feet * 12) + inches;
bmi= (weight*703) / (height * height);
cout<<"BMI: "<<bmi<<endl;
if( bmi < 18.5 ) {
// if condition is true then print the following
cout << "Underwight" << endl;
} else if( bmi >= 18.5 && bmi <= 25 ) {
// if else if condition is true
cout << "Optimal weoght" << endl;
} else {
// if else condition is true
cout << "Overweight" << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.