C Primer Plus(第五版)中文版 程序清单6.19
运行环境:VC6.0
程序如下:
#include <stdio.h>
#define SIZE 10
#define PAR 72
int main (void)
{
int index, score[SIZE];
int sum=0;
float average;
printf("Enter %d golf scores: \n", SIZE);
for(index=0; index<SIZE; index++);
{
scanf("%d", &score[index]);
}
printf("The scores read in are as follows: \n");
for(index=0; index<SIZE; index++)
{
printf("%5d", score[index]);
}
printf("\n");
for(index=0; index<SIZE; index++)
{
sum+=score[index];
}
average=(float)sum/SIZE;
printf("Sum of scores=%d, average=%.2f\n", sum, average);
printf("That's a handicap of %.0f.\n", average-PAR);
return 0;
}
为什么运行后得不到结果 运行结果如下:
Enter 10 golf scores:
101 100 102 103 110 102 99 98 97 96
The scores read in are as follows:
-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460
-858993460-858993460
Sum of scores=-8, average=-0.80
That's a handicap of -73.
Press any key to continue
求高手帮帮忙,解答一下,谢谢了!
[解决办法]
for后面多了一个分号,导致没有数据读入
for(index=0; index<SIZE; index++);{scanf("%d", &score[index]);}
[解决办法]