请问这个scanf为什么不能输入?
#include<stdio.h>#include<ctype.h>
int main(void)
{
double value = 0.0;
double sum = 0.0;
unsigned int count = 0;
char answer = 0;
for(;;)
{
printf("\nEnter a value:");
scanf("%lf",&value);
sum += value;
++count;
printf("\nDo you want countinue. (y or n)?:");
scanf("%c",&answer);
if('n' == tolower(answer))
break;
}
printf("\nyou have input %d number ,and the average of these number is %.2lf",count,sum/count);
return 0;
}
程序如上,其中scanf("%c",&answer);这句,程序直接跳过,不需要输入。请问是那里出错了?执行结果如下:
Enter a value:3
Do you want countinue. (y or n)?:
Enter a value:2
Do you want countinue. (y or n)?:
Enter a value:1
Do you want countinue. (y or n)?:
Enter a value:n
Do you want countinue. (y or n)?:
you have input 4 number ,and the average of these number is 1.75请按任意键继续.
. .