Write a program that requests a person\'s weight and height as input and display
ID: 3535121 • Letter: W
Question
Write a program that requests a person's weight and height as input and displays the
BMI has to be displayed to the nearest whole number
heres my code so far
#include
"stdafx.h"
 
#include
<iostream>
using
namespace std;
int
main ()
{
double
height = 0.0;
double
weight = 0.0;
double
bmi = 0.0;
cout <<
"Enter your height (in inches): ";
cin >> height;
cout <<
"Enter your weight (in pounds): ";
cin >> weight;
bmi = 703 * weight / (height * height);
if
(bmi < 18.5)
{
cout <<
"Your body weight category is underweight." << endl;
}
else
if (bmi = 18.5 < 25)
{
cout <<
"Your body weight category is normal." << endl;
}
else
if (bmi = 25 < 30)
{
cout <<
"Your body weight category is overweight." << endl;
}
else
if (bmi >= 30)
{
cout <<
"Your body weight category is obese." << endl;
}
system (
"pause");
return
0;
Explanation / Answer
Please rate with 5 stars :)
Here is what needs to be done, (a very intelligent way)
Caluculate the BMI, which you already have in the variable bmi.
Now for rounding , do this:
if( (bmi + 0.5) >= (int(bmi) + 1) )
cout << bmi << " rounds to " << int(bmi)+1;
else
cout << bmi << " rounds to " << int(bmi);
Cheers!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.