//This is a BMI calculator
#include<iostream>
#include<string>
using namespace std;
//The function to calculate height in inches
int ConvertToInches(int ft, int ind)
{
int height = 0;
height=ft * 12 + ind;
return (height);
}
//The function to calculate BMI
float BMICalculator(int height,float weight)
{
float BMI = 0.0;
BMI = 703 * weight / (height*height);
return(BMI);
}
//The function to determin health status
string WeightStatus(float BMI)
{
string stu;
if (BMI < 18.5)
stu = "Underweight";
else if ((BMI >= 18.5) && (BMI <= 24.9))
stu = "Normal";
else if ((BMI >= 25.0) && (BMI <= 29.9))
stu = "Overweight";
else
stu = "Obese";
return(stu);
}
int main()
{
int ft = 0, ind = 0;
float weight=0.0;
int height = 0;
float BMI=0.0;
string status;
cout << "BMI Calculator" << endl;
cout << "Enter the patient's height (in ft and inches-Enter 0 0 to stop):" << endl;
cin >> ft >> ind;
cout << "Enter the patient's weight (in pounds):";
cin >> weight;
cout <<endl<< "Height: "<<ft << " feet, "<<ind << " inches" << endl;
cout << "Weight: " << weight << " pounds" << endl;
// Calling three functions to determine the final result
height=ConvertToInches(ft, ind);
// cout << height << endl;//put a test here to check the above function
BMI=BMICalculator(height,weight);
// cout << "BMI= " << BMI << endl;// Test the BMI value here
status = WeightStatus(BMI);
// cout << status << endl;//Test the result here
cout << "Your BMI is " << BMI << ", indicating your weight is in " << status<< " category for adults of your height."<<endl;
system("pause");
return 0;
}
回到主页
回到目录