首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C Primer Plus(第五版)中文版 程序清单6.19解决方案

2012-03-17 
C Primer Plus(第五版)中文版 程序清单6.19运行环境:VC6.0程序如下:#include stdio.h#define SIZE 10#de

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后面多了一个分号,导致没有数据读入

C/C++ code
for(index=0; index<SIZE; index++);{scanf("%d", &score[index]);}
[解决办法]
探讨

for后面多了一个分号,导致没有数据读入
C/C++ code

for(index=0; index<SIZE; index++);
{
scanf("%d", &amp;score[index]);
}

[解决办法]
再++
探讨
引用:

for后面多了一个分号,导致没有数据读入
C/C++ code

for(index=0; index<SIZE; index++);
{
scanf("%d", &amp;amp;score[index]);
}
++

热点排行