#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# if statment help

Posts: 11Member
I am wanting to write a program for a BMI calculator that eventually will record details for several entries.

However to start with I need to be able to just complete one calculation.

Below is my code which works up to the if statement what I am trying to do is once I have completed the calculation be able to take that result and use the if statement to indicate if the result is normal, under or over.

I don't know how to take the result and put it into the if statement.

[code]
#include
#include
int main()
{

float height, weight,bmi;

printf("Enter Weight in Kg's and Height in METERS
");
scanf("%f%f", &weight, &height );

bmi = weight/(height*2);

printf("Your BMI is %.2f
",bmi);

scanf("%");

if("%f"<=25){
printf("your weight is normal
");
}

return(0);
[/code]
· ·

• Posts: 12Member
I have written the code,that gives the right result:
#include
#include
int main()
{
float height, weight,bmi;
printf("Enter Weight in Kg's and Height in METERS
");
scanf("%f%f", &weight, &height );
bmi = weight/(pow(height,2));
printf("Your BMI is %.2f
",bmi);
if (bmi<=25){
printf("your weight is normal
");
}
return(0);
}

Have you understood this,or shall I explain you something? :)
· ·