H5W3

# 这道题应该如何做。有大神帮忙么？

Overview

Write a program to calculate the user’s body mass index (BMI).
Directions
A person’s body mass index (BMI) is calculated using their height and weight. The formula for BMI is:

BMI = kg / m2

Where kg is the person’s mass in kilograms, and m2 is their height in metres squared.
Write a program to calculate a person’s BMI. Your program should first ask the user to enter their height in feet and inches, then their weight in pounds. Your program should then use the data to calculate the person’s BMI. Your program should also display the person’s height and weight in metres and kilograms. There are 12 inches in a foot, 3.28084 feet in a metre, and 2.20462 pounds in a kilogram.

The listing below shows an example of what the input and output for this program might look like. Input by the user is listed in blue.

What is your height?
Feet: 5
Inches: 10
What is your weight (lbs)? 160

Height (m): 1.778
Weight (kg): 72.5749
BMI: 22.9574

### 回答

``````#include <iostream>
using namespace std;
int main()
{
float feet, inches, weight, m, kg, bmi;
cout << "Feet:";
cin >> feet;
cout << "Inches:";
cin >> inches;
cout << "What is your weight (lbs)?";
cin >> weight;
m = (feet + inches / 12.0) / 3.28084;
cout << "Height (m): " << m << endl;
kg = weight / 2.20462;
cout << "Weight (kg):" << kg << endl;
bmi = kg / m / m;
cout << "BMI:" << bmi << endl;
return 0;
}
``````

Feet:5
Inches:10
What is your weight (lbs)?160
Height (m): 1.778
Weight (kg):72.5749
BMI:22.9574