不提示选择,直接循环
#include<stdio.h>#include<ctype.h>
int main(void)
{
char answer='N';
double total=0.0;
double value=0.0;
unsigned int count=0;
printf("\nthis program calculates 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 N0):");
scanf("%c",&answer);
if(tolower(answer)=='n')
break;}
printf("\nthe average is %.2lf\n",total/count);
return 0;
}