帮帮忙看看这个程序哪里错了..

liumangmaoenen 2010-04-06 01:20:23
#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]); // read in the ten scores
printf("The scores read in are as follows:\n");
for (index = 0; index < SIZE; index++)
printf("%5d", score[index]); // verify input
printf("\n");
for (index = 0; index < SIZE; index++)
sum += score[index]; // add them up
average = (float) sum / SIZE; // time-honored method
printf("Sum of scores = %d, average = %.2f\n", sum, average);
printf("That's a handicap of %.0f.\n", average - PAR);

return 0;
}

我用VC 6.0,但显示有一个error(s),那究竟哪里错了?

我按照c primer plus编出来的..
...全文
163 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
huanmie_09 2010-04-07
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 liumangmaoenen 的回复:]
那请问应该用什么编译器?(我觉得VC6.0用起来不爽..)

VS2005?VS2008?还是别的什么?
[/Quote]
我的结果是在vs 2008下跑的.
东大坡居士 2010-04-06
  • 打赏
  • 举报
回复
用GCC吧,估计是你的编译器那块设置的有问题
liumangmaoenen 2010-04-06
  • 打赏
  • 举报
回复
那请问应该用什么编译器?(我觉得VC6.0用起来不爽..)

VS2005?VS2008?还是别的什么?
harizu76 2010-04-06
  • 打赏
  • 举报
回复
没发现错误哦
McFate 2010-04-06
  • 打赏
  • 举报
回复
应该没错
huanmie_09 2010-04-06
  • 打赏
  • 举报
回复
应该是你编辑器的问题了。
elegant87 2010-04-06
  • 打赏
  • 举报
回复

#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]); // read in the ten scores
printf("The scores read in are as follows:\n");
for (index = 0; index < SIZE; index++)
printf("%5d", score[index]); // verify input
printf("\n");
for (index = 0; index < SIZE; index++)
sum += score[index]; // add them up
average = (float) sum / SIZE; // time-honored method
printf("Sum of scores = %d, average = %.2f\n", sum, average);
printf("That's a handicap of %.0f.\n", average - PAR);

return 0;
}

代码是没有问题的。给你推荐几个编译器吧。Dev_C++和C Free很好用的。
liumangmaoenen 2010-04-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 huanmie_09 的回复:]
引用 5 楼 liumangmaoenen 的回复:
不是吧...

我自己写了两次还是错...

报啥错?我是直接copy了你的代码运行,没问题.2楼的就是运行结果.
[/Quote]

怎么我用的VC 6.0会显示如下:

SSS.exe - 1 error(s), 0 warning(s)

难道编译器的问题?需不需要换个别的?
huanmie_09 2010-04-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liumangmaoenen 的回复:]
不是吧...

我自己写了两次还是错...
[/Quote]
报啥错?我是直接copy了你的代码运行,没问题.2楼的就是运行结果.
liumangmaoenen 2010-04-06
  • 打赏
  • 举报
回复
不是吧...

我自己写了两次还是错...
wade_2003 2010-04-06
  • 打赏
  • 举报
回复
我用VC6运行了,一切正常啊,估计是你书写错误
FingerStyle 2010-04-06
  • 打赏
  • 举报
回复
没问题啊
huanmie_09 2010-04-06
  • 打赏
  • 举报
回复
报什么错?
在vs 2008下运行正常.
Enter 10 golf scores:
1
2
3
4
5
6
7
8
9
10
The scores read in are as follows:
1 2 3 4 5 6 7 8 9 10
Sum of scores = 55, average = 5.50
That's a handicap of -67.
Dstnoe 2010-04-06
  • 打赏
  • 举报
回复
没错啊!用vc6.0运行了,用C-free运行了,都没错啊? 楼主好好看看源代码有没有 书写错误!

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧