Question #114923

BMI formula: BMI = weight /(height x height)

BMI Weight status

Below 18.5 Underweight

18.5‐24.9 Healthy

25.0‐29.9 Overweight

30.0 and above Obese

Write a program that calculates a person’s BMI and displays the weight status according to the BMI

value, indicating whether the person is underweight, healthy, overweight or obese. The BMI weight

statuses and related values are listed in the above table.

The program should have the following functions:

1.1. getData that prompts and returns their weight and height;

1.2. calcBMI to calculate the BMI ;

1.3. displayFitnessResults to display the BMI and relevant weight status message;

1.4. main function

Expert's answer

#include <iostream>
#include <string>


void getData(double& weight, double& height)
{
    
    std::cout << "Please enter your weight (in kilograms): ";     
    std::cin >> weight;
    
    std::cout << "Please enter your height (in meters): ";
    std::cin >> height;
}


double calcBMI(double weight, double height)
{
    double BMI = weight /(height * height);
    return BMI;
}

std::string displayFitnessResults(double BMI)
{
    std::string res = "";
    
    if(BMI < 18.5)
        res = "Underweight";
    else if(BMI >= 18.5 && BMI <= 24.9)
        res = "Healthy";
    else if(BMI >= 25.0 && BMI <= 29.9)
        res = "Overweight";
    else if (BMI >= 30.0)
        res = "Obese";
    
    return res;
}

int main()
{
    double weight, height;     
    getData(weight, height);  


    double BMI = calcBMI(weight, height);
    std::cout << "Your Body Mass Index (BMI) is " << BMI << std::endl;    
    std::string ResFitness = displayFitnessResults(BMI);    
    std::cout << ResFitness << std::endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS