#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char answer='N';
double total=0.0;
double value=0.0;
int count=0;
printf("\nThis program calculation the the average of any number of values.");
for(;;)
{
printf("\nEnter a value:");
scanf("%lf",&value);
total+=value;
++count;
printf("Do you want to enter another value?(Y or N):");
scanf("%c",&answer);
if(tolower(answer)=='n')
break;
system("pause");
}
printf("The average is %.2lf\n,total/count");
1. scanf("%lf",&value);------这一句后面应该跟一句:getchar (); 用来接收回车; 否则下一个scanf("%c",&answer); 会接收回车符,程序会直接运行到 system("pause"); 这一句。
2.printf("The average is %.2lf\n,total/count");,双引号写错了位置;应该是这样写:
printf("The average is %.2lf\n",total/count);