I am trying to learn C and came up with the following small program.
#include "stdafx.h" void main() { double height = 0; double weight = 0; double bmi = 0; printf("Please enter your height in metres\n"); scanf_s("%f", &height); printf("\nPlease enter your weight in kilograms\n"); scanf_s("%f", &weight); bmi = weight/(height * height); printf("\nYour Body Mass Index stands at %f\n", bmi); printf("\n\n"); printf("Thank you for using this small program. Press any key to exit"); getchar(); getchar(); }
The program compiles fine, but the answer returned by the program does not make sense. If I enter 1.8 for height and 80 for weight, bmi is like 1. # NF00, which doesn't make sense.
What am I doing wrong?
Matthew
source share