write a program in c++,The body mass index (BMI = mass / height^2 of a person is
ID: 3760571 • Letter: W
Question
write a program in c++,The body mass index (BMI = mass / height^2 of a person is used to check whether a person’s weight is normal or not, (see the BMI table below). It is defined as the mass of the person in kg divided by the square of his or her height in meters. Write a program that prompts the user to enter his/her first name, mass, and height. The program finds the BMI of the user. The program prints the name of the user in a column of 10 characters wide and left justified, the BMI with only two decimal digits
Explanation / Answer
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
float weight;
float height;
float bmi;
char response;
char name[10];
do
{
cout << "***************************** ";
cout << "enter your name : ";
cin>> name;
cout << "Please enter your weight (lbs): ";
cin >> weight;
cout << "Please enter your height (inches): ";
cin >> height;
bmi = (weight / pow(height,2)) *703;
cout<<" ";
cout << fixed << showpoint << setprecision(2);
cout<<name<<" your BMI is " << bmi << endl;
if (bmi < 18.5)
{
cout << "You are underweight " <<name<< endl;
cout << "Eat more!!" << endl;
}
else if (bmi >= 18.5 && bmi <25)
cout << "You are normal " <<name<<endl;
else if (bmi >= 25 )
cout << "You are overweight "<<name<<endl;
else
cin.get();
cin.get();
cout << endl;
cout << "Would you like to enter the information again? ";
cin >> response;
}
while (toupper(response) == 'Y');
cout << "Okay, see you next time.." << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.