Game Plan Fitness club requires a system that will help their members keep up to date with their BMI after each training session. The system will allow users to enter their weight and height and then calculate each member’s BMI, the system must determine their health status based on the BMI. Use the formula BMI=wieght/(height)^2 , assuming that height is entered in meters and weight is entered in kilograms. Create a function that calculate the BMI, and use a post test loop with weight of -1 to terminate the loop.
#include <iostream>
using namespace std;
float BMI(float h, float w){
return w / (h * h);
}
int main(){
float w, h;
do{
cout<<"Input weight: ";
cin>>w;
if(w < 0) break;
cout<<"Input height: ";
cin>>h;
float bmi = BMI(h, w);
cout<<"BMI: "<<bmi<<endl;
cout<<"Health Status: ";
if(bmi < 18.4) cout<<"Underweight\n";
else if(bmi < 24.9) cout<<"Healthy weight\n";
else if(bmi < 29.9) cout<<"Overweight\n";
else cout<<"Obesity\n";
}while(w != -1);
return 0;
}
Comments
Leave a comment