I'm trying to write a program that calculates BMI and the math checks out for the equation. My problem is getting it to prompt the statement that corresponds with the BMI range that I've programmed. This is what I got.
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int Weight;
int Height;
float BodyMassIndex;
cout << " In order to calculate your BMI, please enter your weight in pounds and your height in inches in the following prompts." ;
cout << "Your Body Mass Index is:" << setprecision(2) << fixed << BodyMassIndex << endl;
if(BodyMassIndex < 15.0)
{
cout << "You are very severely underweight, get medical help. " << endl;
}
if((BodyMassIndex >= 15.0) && (BodyMassIndex <= 15.9));
{
cout << "You are severely underweight, you really could use a hamburger." << endl;
}
if ((BodyMassIndex >= 16.0) && (BodyMassIndex <= 18.4));
{
cout << "You are underweight, try adding a few more pounds but be wise about it." << endl;
}
if ((BodyMassIndex >= 18.5) && (BodyMassIndex <= 24.9));
{
cout << "You are at a healthy weight, now just maintain it." << endl;
}
if ((BodyMassIndex >= 25.0) && (BodyMassIndex <= 29.9));
{
cout << "You are overweight try eating a little less or get more exercise." << endl;
}
if((BodyMassIndex >= 30.0) && (BodyMassIndex <= 34.9));
{
cout << "You are at class one obesity, moderately obese." << endl;
}
if((BodyMassIndex >= 35.0) && (BodyMassIndex <= 40.0));
{
cout << "You are at class two obesity, severely obese." << endl;
}
if(BodyMassIndex > 40.0);
{
cout << "You are at class three obesity, very severely obese." << endl;
}
return 0;
I applied the changes and I got what I wanted. I also changed the set precision to one to fix the error two decimal places would have with the rest of the program. Thanks!
Note that setprecision only affects how things are printed, it doesn't affect any if-else logic. What I said before still applies, unless you changed the actual logic (Which you may have done, I don't know exactly what you changed).