当前位置:H5W3 > 问答 > 正文



Write a program to calculate the user’s body mass index (BMI).
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;

What is your weight (lbs)?160
Height (m): 1.778
Weight (kg):72.5749


未经允许不得转载:H5W3 » 这道题应该如何做。有大神帮忙么?

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址