Reputation: 55
I am attempting to write a program that will take a user's input of weight and height and then return a BMI value and tell the user if they are under/over or normal weight. The code compiles with no errors, however no matter what numbers I input for weight and height, the result is always "You have a BMI of 0 and your weight status is overweight". Is there something wrong with my code or is my math just incorrect?
#include <stdio.h>
int main()
{
double wt_lb, ht_in, bmi, ht_ft;
printf("Please enter your weight in whole pounds: ");
scanf("%lf", &wt_lb);
printf("Please enter your height in whole inches: ");
scanf("%lf", &ht_in);
ht_ft = ht_in/12;
bmi = (703*wt_lb)/(ht_ft*ht_ft);
if (bmi < 18.5) {
printf("You have a BMI of %.lf, and your weight status is underweight\n" &bmi);
} else if (bmi >= 18.5 && bmi < 25) {
printf("You have a BMI of %.lf, and your weight status is normal\n", &bmi);
} else {
printf("You have a BMI of %.lf, and your weight status is overweight\n", &bmi);
}
}
Upvotes: 1
Views: 12863
Reputation: 106102
Remove &
from aal of your printf
's argument.
printf("You have a BMI of %f, and your weight status is underweight\n" &bmi);
^
|
Remove this &
It should be
printf("You have a BMI of %f, and your weight status is underweight\n", bmi);
Also never use %lf
specifier for double
in printf
(in scanf
you have to use) instead use %f
.
Upvotes: 2
Reputation: 11
In the printf statement don't use &bmi, use simple bmi. It should work
Upvotes: 1