新人对着书打的代码,不知道为什么运行不正常。求触帮助OTZ
对着C Primer Plus第五版打的示例程序,用的是VS2012
//第三章3.1示例程序
#include <stdio.h>
int main(void)
{
float weight;
float value;
printf("Are you worth your weight in rhodium?\n");
printf("Let's check it out.\n");
printf("Please enter your weight in pounds:");
scanf_s("%f",&weight);
value = 770 * weight * 14.5833;
printf("Your weight in rhodium is wroth $%.2f.\n",value);
printf("You are easily worth that!If rhodium prices drop,\n");
printf("eat more to maintain your value.\n");
getchar();
return 0;
}
最后的getchar()函数是自己加的,这样运行后,输入了weight后会想没有getchar()一样一闪而过然后关闭程序,后面的出黑粗内容。但是我已经在最后加入了这个函数,为什么还是会一闪而过。在value = 770 * weight * 14.5833;后面加入getchar()函数就可以正常运行?