# include & lt; stdio.h>
# include & lt; Ctype. H>
# include & lt; Conio. H>
Int main (void)
{
Char answer='N';
Double total=0.0;
A double value=https://bbs.csdn.net/topics/0.0;
int count=0;
Printf (" \ nthis program calculates the average of any number of values. ");
For (; ; )
{
Printf (" \ n the Enter a value: ");
Lf the scanf (" % ", & amp; Value);
Total +=value;
+ + count;
Printf (" \ n Do you want to enter another value? (Y/N) : ");
The scanf (" % c ", & amp; Answer);
If (tolower (answer)=='n')
break;
}
Printf (" \ nthe business is %. 0 lf \ n ", total/count);
_getch ();
return 0;
}
CodePudding user response:
for (; ; )
{
Printf (" \ n the Enter a value: ");
Lf the scanf (" % ", & amp; Value);
Total +=value;
+ + count;
Printf (" \ n Do you want to enter another value? (Y/N) : ");
getchar();
The scanf (" % c ", & amp; Answer);
If (tolower (answer)=='n')
break;
}
Add a getchar (), probably simply because there is first the scanf newline, just in a second the scanf, use first getchar () absorbed the newline character, if that's ok
CodePudding user response:
the scanf (" % c ", & amp; Answer);
This statement before adding a getchar ();
Because of this statement is % c, '\ n' match the input buffer, this' \ n 'is an input on the left,