BMI Program

Need help with a program that will not display if and else if statements. Am I doing something wrong? Any helpful tips would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//This program is used to calculate the BMI of a person
//and display whether the person is overweight or not
//BMI = weight*703/height^2
//weight is measured in pounds/lbs
//height is measured in inches

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

	double weight, height;
	float BMI;

	cout<<"Enter your weight in pounds: "<<endl;
	cin>>weight;
	cout<<"Enter your height in inches: "<<endl;
	cin>>height;
	BMI = (weight*703)/(height*height);
	cout<<fixed<<showpoint<<setprecision(1);
	cout<<"Your BMI is "<<BMI<<endl;

	if (BMI<18.5)
	{
	cout<<"You are underweight. Eat more food, your too skinny!\n"<<endl;
	}

	else if ((BMI<18.5) && (BMI>25))
	{
	cout<<"You have optimal weight. You are healthy, well done!\n"<<endl;
	}

	else if (BMI>25)
	{
	cout<<"You are overweight. Stop eating so much junkfood and excercise!\n"<<endl;
	}
	
system("pause");
return 0;
}


It only displays the first half of the code and completely skips over the if and else if statements for some reason.
Last edited on
Well, it's not possible for the condition: (BMI<18.5) && (BMI>25) to be true. A number can't be both less than 18.5 and greater than 25.
The prompt says a BMI between 18.5 and 25 is optimal weight. Then should it be (BMI>=18.5 && BMI<=25).

Oh okay, thank you! It works now! Syntax is really important, I'll take note of that for next time.

I didn't even realize that... I can't believe I missed that...
Last edited on
Topic archived. No new replies allowed.