就是一次输入后,回车就报错,我本来是想输入后回车进入for循环接受第二次输入的。。。。
用的是vc
程序代码:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
struct score
{char name[10];
float math,eng;
};
main()
{ struct score s[5]; int i; double avg[5];
for(i=0;i<5;i++)
{
printf("name:");
gets(s[i].name);
printf("maths english:");
scanf("%f%f",&s[i].math,&s[i].eng);
}
for(i=0;i<5;i++)
avg[i]=(s[i].math+s[i].eng)/2;
for(i=0;i<5;i++)
{
printf("%3.1f\t",avg[i]);
}
}

程序代码:/**
* file_name: test.c
* description:
*
* version: 1.0
* created: 17:14 2009-8-2
* revision: none
* compiler: VC6.0
*
* author: prankmoon@* company:
*/
#include <stdio.h>
#include <stdlib.h>
struct score
{
char name[20]; // 更长了,因为我一不小心胡乱按键盘就溢出了
float math;
float eng;
};
int main(void)
{
int i;
float avg[5] = {0}; // 改成了float型,double在这里并不能提高精度
struct score s[5];
for(i=0; i<5; i++)
{
printf("name: ");
/* 增加下面这一行,但有其缺陷,具体的你可以参考这篇文章:
http://blog.*/
fflush(stdin);
gets(s[i].name); // gets函数已经不推荐使用了,详见《C专家编程》P42
printf("maths english: ");
/* 输入的参数之间还是用空格或者逗号分开为佳 */
scanf("%f %f",&(s[i].math), &(s[i].eng));
}
for(i=0; i<5; i++)
{
avg[i] = (s[i].math + s[i].eng) / 2;
printf("%3.1f\t\n", avg[i]);
}
return 0;
}