33,311
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<ctype.h>
int main(void) {
char answer = 'n';
double total = 0.0;
double value = 0.0;
int count = 0;
printf("\nThis program calculates the average of any number of values .\n");
for ( ;; )
{
printf("\nEnter a value :");
scanf_s("%lf", &value);
total = total + value;
++count;
/* Check for more input */
printf("Do you want to enter another value?(Y or N): ");
scanf_s("%c", &answer,1);
if (tolower(answer) == 'n')
break;
}
/* Output the average to 2 decimal place */
printf("\nThe average is %.2lf\n", total / count);
return 0;
}
printf("\nEnter a value :");
scanf_s("%lf", &value);
total = total + value;
++count;
//请今后要用
int c;
scanf("%c",&c);
//时,都改为
char s[2];
int c;
scanf("%1s",s);
c=s[0];