急!!!麻烦大家帮忙看一下,这个 for 循环语句哪里错了,自学C语言苦逼一枚
//Program 4.6 The almost infinite loop--computing an average#include<stdio.h>
#include<ctype.h>
int main(void)
{
double total =0.0;
double value = 0.0;
unsigned int count = 0;
char answer = 'n';
printf("\nThis program calculates the average of any numbers of values.");
for( ;; )
{
printf("\nPlease enter a value you wanna count the average: ");
scanf("%lf", &value);
total += value;
++count;
printf("\nDo you wanna enter some more values?(y or n): ");
scanf("%c", &answer);
if(answer =='n')
break;
}
printf("\nThe average of these %d values is %.2lf\n", count, total/count);
return 0;
}
各位大神,这个程序执行之后,存在2个问题:
1. for一直是死循环,也就是说,break根本不执行
2. printf("\nDo you wanna enter some more values?(y or n): ");这个语句无法输入,只是个摆设
急疯了。。。。恳请大家帮忙看看,给个意见,谢谢啊~