,第一个getchar()为什么放在那个位置可以,而放在另外的位置不可以,求解释一i下,通俗一点最好。
#include<stdio.h>
int main(void)
{
printf("本程序介绍相当与你体重的相等重量的白金价值,体重单位是磅,价值单位是美元。\n");
float weight;
float value;
printf("Are you worth your weight in platinum!\n");
printf("Let us check it out!\n");
printf("Please enter your weight:");
scanf_s("%f",&weight);
value = 1700.0 * weight* 14.5833;
printf("Your weight in platinum is worth $%.2f.\n", value);
getchar();
printf("You are easily worth that! If platinum prices drop,\n");
printf("ear more to maintain your value \n");
getchar();
return 0;
}
第二个getchar()时,程序才等待键盘输入,实际起到了暂停的作用。追问
奥,我有点明白了,那为什么我把第一个getchar()删除程序就不会暂停呢
追答如果把第一个getchar()去掉,因为你前面输入时的回车符一直暂存在输入缓冲区中,当执行第二个getchar时,就把回车符读出,这时不需要等待你输入什么字符,程序接着往下运行了。所以,你感觉不到暂停等待输入的现象。