我正在努力学习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'。](http://stroustrup.com/bs_faq2.html#void-main) – chris 2012-07-26 14:42:25
@chris好东西知道。我总是被教导,'void main'是用于C,'int main'用于C++。我想知道新C/C++程序员做这件事的习惯是从哪里来的。 – Darthfett 2012-07-26 18:53:35
@Darthfett,我认为有几本书使用'void main'。我想这就是所有这些都是从那里传来的。 – chris 2012-07-26 18:58:25