我正在尝试学习C语言,并写了下面这个简短的程序。
#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();
}
程序编译完美,但程序返回的答案毫无意义。如果我输入身高为1.8米,体重为80千克,则BMI值显示为1.#NF00,这没有任何意义。
我做错了什么?
%lf
吗?无论如何,你不应该使用void main
。 - chrisvoid main
用于 C,而int main
用于 C++。不知道新的 C/C++ 程序员这种习惯是从哪里来的。 - Casey Kuballvoid main
。 我可以想象所有这些都是从那里传递下来的。 - chris