6
I’m doing a simple C-program to calculate body mass index. However, it is returning a different value (wrong) than a common calculator.
#include <stdio.h>
int main() {
float height, weight, imc;
printf("Hello World!\nWhat's your height?");
scanf("%f", &height);
printf("What's your weight?");
scanf("%f", &weight);
imc = height / (weight * height);
printf("%f", imc);
getch();
return 0;
}
Expression: Height / weight²
What values are returning? Give an example, please
– Victor Alencar Santos
If it’s weight, you gotta put
imc = height / (weight * weight );
– CesarMiguel
The result is relative because it depends on the height and weight inserted. But if I put 1.80 and 80 the correct result would be 24.69 but returns 0.555556
– user28062
BMI is weight (mass) divided by height squared, and not the other way around. And in your code, you’re dividing height by height times weight, which simply gives the inverse of the weight...
– mgibsonbr