【发布时间】:2012-07-25 04:29:12
【问题描述】:
我正在努力学习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吗?无论如何,you shouldn't usevoid main. -
@chris 很高兴知道。我总是被告知
void main是用于 C,而int main是用于 C++。我想知道新 C/C++ 程序员这样做的习惯从何而来。 -
@Darthfett,我认为有几本书使用
void main。我想这就是所有这些都被传递的地方。
标签: c types primitive-types