Need Help

Write a program to help a clinic calculate the Body Mass Index (BMI) of 50 patients. The program asks a person for his height in meters and his weight in kilograms.It then computes his BMI using the following equation:
BMI=weight/height^2
Then the program prints out the BMI and a comment on it. The comment is Thin if the BMI is less than 200, Normal if between 20 and 25, Overweight if between 25 and 30, and Fat if bigger than 30.

This is what i did.

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
double weight,height;
double BMI;

printf("Enter weight and height\n");
scanf("&d&d", &weight, &height);

for(int i=1;i<=50;i++){
BMI=weight/pow(height,2);
if(BMI<=20){
printf("BMI = %d Thin\n", BMI);
}
else if(BMI<=20 && BMI<=25){
printf("BMI = %d Normal\n",BMI);
}
else if(BMI<=25 && BMI<=30){
printf("BMI = %d Overweight\n",BMI);
}
else {printf("BMI = %d Fat\n",BMI);
}
}
getch();
}
Tip: Use the code blocks (on the right, under format, button with "<>")

On this line else if(BMI<=20 && BMI<=25){, you are checking if BMI is less than 20 and less than 25 (same goes for the 'Overweight' one).

To get what you are looking for, change it to:
else if(BMI>=20 && BMI<=25){
Last edited on
Thank you my friend
Topic archived. No new replies allowed.