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)
#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.
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.
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.