In: Computer Science
Language C++
Ask the user to enter their weight (in pounds) and their height in inches. Calculate their Body Mass Index (BMI) and tell them whether they are underweight, overweight, or at optimal weight.
BMI formula: weight * 703 / (height * height)
Optimal weight is a BMI from 19 to 26. Lower is underweight, higher is overweight.
Prompts:
Enter your weight (in pounds): [possible user input: 144]
Enter your height (in inches): [posible user input: 73]
Possible Outputs:
Your BMI is 18.9964, which means you are underweight.
Your BMI is 29.2612, which means you are overweight.
Your BMI is 25.8704, which means you are at optimal weight.
Notes and Hints:
1) For simplicity, assume user entries will be in whole numbers. However, BMI must be calculated with decimals.
2) You must use an if/else if structure for this
C++ code:
#include <iostream>
using namespace std;
int main(){
//initializing weight,height and BMI
double weight,height,bmi;
//asking for weight
cout<<"Enter your weight (in pounds):
";
//accepting it
cin>>weight;
//asking for height
cout<<"Enter your height (in inches):
";
//accepting it
cin>>height;
//finding bmi
bmi=weight*703/(height*height);
//checking if BMI is less than 19
if(bmi<19)
//printing underweight
cout<<"Your BMI is
"<<bmi<<", which means you are
underweight."<<endl;
//checking if BMI is greater than 26
else if(bmi>26)
//printing overweight
cout<<"Your BMI is
"<<bmi<<", which means you are
overweight."<<endl;
else
//printing optimal weight
cout<<"Your BMI is
"<<bmi<<", which means you are at optimal
weight."<<endl;
return 0;
}
Screenshot:
Input and Output: