运行结果错误,哪儿错了呢?
题目是编写程序,从输入文件“data.in”中读入某班n个学生信息,建立学生数据结构体,包括学号、姓名和三门课的成绩,计算输出该班各门课的平均分。
我的编码是编写程序
#include<stdio.h>
int main()
{
struct st{
char num[10];
char name[30];
unsigned int scores[3];
};
unsigned int scores[3];
float aver;
int i, sum, n;
struct st stu[3];
FILE *fp = fopen("data2.in", "r");
if(fp==NULL){
printf("error 1\n");
return 1;
}
fscanf(fp, "%d", &n);
if(n <=1||n>=60){
printf("error 2\n");
return 2;
}
for(i = 0; i <n; i++)
{
fscanf(fp, "%s %s %d %d %d", &stu[i].num, &stu[i].name, &stu[0].scores[i], &stu[1].scores[i], &stu[2].scores[i]);
sum==stu[0].scores[i]+stu[1].scores[i]+stu[3].scores[i];
aver==sum%3;
printf("math:%d\n, English:%d\n, C-progra:%d\n");
}
fclose(fp);
return 0;
}
[解决办法]
sum==stu[0].scores[i]+stu[1].scores[i]+stu[3].scores[i]; aver==sum%3;