# Thread: C++ programming. i need help in this.plz help me!

1. ## C++ programming. i need help in this.plz help me!

Between 18.5 and 25.0 (inclusive)

i need to put that statement in if loop but its not working
my if loop is like this

if (B<25.0 | B>18.5)

how can i get it right ?

2. ## Re: C++ programming. i need help in this.plz help me!

the | should be replaced with ||
| is a bitwise or

Also since the statement said inclusive you should have

if(B<=25.0 || B>=18.5)

3. ## Re: C++ programming. i need help in this.plz help me!

#include <iostream>

using namespace std;

int main()
{
double h,w;
double B=1;
cout<<"Please enter your weight in kg :"<<endl;
cin>>w;
cout<<"Please enter your height in meters :"<<endl;
cin>>h;
B*=w/(h*h);
cout<<"The BMI is :"<<B<<endl;

if (B<=25.0 || B>=18.5)

cout<<"This is normal weight"<<endl;

else if (B>25.1)

cout<<"This is overweight"<<endl;

else if (B<18.0)
cout<<"This is underweight"<<endl;

return 0;
}

this is my code...if the weight is less than or more than the normal it give both the statements and i only need the true one.

4. ## Re: C++ programming. i need help in this.plz help me!

use the brackets after your if { } else if { } else if { }

other wise you are doing something called chaining if statements which is not what you want

5. ## Re: C++ programming. i need help in this.plz help me!

its still the same problem if the weight is over it gives normal no matter what.....my first if statement is wrong i know that but i cant figure it out how to get those values and the values between in it, just for the normal weight like 18-25.

6. ## Re: C++ programming. i need help in this.plz help me!

give me the h,w values you are using to test it out.

7. ## Re: C++ programming. i need help in this.plz help me!

3. Body Mass Index
The Body Mass Index (BMI) is one of the calculations used by doctors to assess an adult’s health.
The doctor measures the patient’s height (in metres) and weight (in kilograms), then calculates the BMI using the formula

Write a program which prompts for the patient’s height and weight, calculates the BMI, and displays the corresponding message from the table below.

BMI Category Message
More than 25 Overweight
Between 18.5 and 25.0 (inclusive) Normal weight
Less than 18.5 Underweight

Sample Input 1 (user input is in italics)
Enter weight: 69
Enter height: 1.73
Output for Sample Input 1
Normal weight
Explanation for Output in Sample Input 1
The BMI is 69=(1:73 _ 1:73), which is approximately 23.0545. According to the table, this is a “Normal weight”.
Sample Input 2 (user input is in italics)
Enter weight: 84.5
Enter height: 1.8
Output for Sample Input 2
Overweight
Explanation for Output in Sample Input 2
The BMI is 84.5/(1.8 times 1:8), which is approximately 26.0802. According to the table, this is “Overweight”.

this is the whole question.

8. ## Re: C++ programming. i need help in this.plz help me!

oh, sorry, you should use an and statement not an or, use &&, instead of ||

9. ## Re: C++ programming. i need help in this.plz help me!

thank you so much ....it works now!