/* BMI.CPP This program prompts the user for his weight in pounds and height in inches, computes the Body Mass Index (BMI) and displays "Underweight" if BMI is less than 18, "Normal" if BMI is between 18 and 25, and "Overweight" if BMI is greater than 25. BMI is defined as weight, in kilograms, divided over the squared height, in meters. */ #include int BodyMassIndex(double weight, double height) // Takes weight in kilograms and height in meters. // Returns the value of BMI rounded to the nearest integer. { double bmIndex; bmIndex = weight / (height * height); return int(bmIndex + .5); // round to the nearest integer } int main() { const double kgInPound = 0.4536, metersInInch = 0.0254; double weight, height; int BMI; cout << "Enter your height in inches ==> "; cin >> height; cout << "Enter your weight in pounds ==> "; cin >> weight; weight = weight * kgInPound; // or: weight *= kgInPounds; height = height * metersInInch; // or: height *= metersInInch; BMI = BodyMassIndex(weight, height); cout << "Your BMI = " << BMI << endl; if (BMI < 18) cout << "Underweight" << endl; else if (BMI <= 25) cout << "Normal" << endl; else cout << "Overweight" << endl; return 0; }