as12350991 2020-10-13 21:55 采纳率: 50%
浏览 62
已采纳

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

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
用C++

  • 写回答

2条回答 默认 最新

  • threenewbee 2020-10-13 23:56
    关注
    #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

    问题解决的话,请点采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染