我目前正在阅读 Ivor Horton 的《Beginning C》。无论如何,我的不确定是在继续之前for
打印我的声明两次。printf
我确定我做错了什么,但我直接从书中复制了代码。如果这很重要,我正在使用 Dev-C++。这是代码...谢谢
#include <stdio.h>
#include <ctype.h> // For tolower() function //
int main(void)
{
char answer = 'N';
double total = 0.0; // Total of values entered //
double value = 0.0; // Value entered //
int count = 0;
printf("This 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 N): ");
scanf("%c", &answer);
if(tolower(answer) == 'n')
break;
}
printf("The average is %.2lf.", total/count);
return 0;
}