我正在努力學習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