July 26th, 2013, 01:28 PM
If statment help
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.
float height, weight,bmi;
printf("Enter Weight in Kg's and Height in METERS \n");
scanf("%f%f", &weight, &height );
bmi = weight/(height*2);
printf("Your BMI is %.2f\n",bmi);
printf("your weight is normal\n");
Comments on this post
July 26th, 2013, 01:55 PM
Try to separate the input with a space:
What do you try to do with this:
scanf("%f %f", &weight, &height );
You should use the proper variable (bmi) in the if-statement.
July 26th, 2013, 03:53 PM
That is utter nonsense.
The scanf does nothing. And the if statement is comparing the address with 25. Since the first K or so of memory belongs to the operating system, such as the interrupt vector table, I think it's a very safe guess that that string literal, which is co-located with the program image in RAM, is far greater than memory address 25.