结构处理考试成绩,求总分与平均分出现错误。
#include <stdio.h>void main()
{
struct score
{
char name;
int chn,math,eng;
};
typedef struct score score;
score student[10];
int c_sum=0,m_sum=0,e_sum=0;
int c_ave,m_ave,e_ave;
int count;
int i;
printf("How many students are there?=====>>>\n");
scanf("%d",&count);
for(i=0;i<count;i++)
{
printf("Please input the name of student %d=====>\n",i+1);
scanf("%d",&student[i].name);
printf("Please input the chinese score of student %d=====>\n",i+1);
scanf("%d",&student[i].chn);
c_sum+=student[i].chn;
printf("Please input the math score of student %d=====>\n",i+1);
scanf("%d",&student[i].math);
m_sum+=student[i].math;
printf("Please input the english score of student %d=====>\n",i+1);
scanf("%d",&student[i].eng);
e_sum+=student[i].eng;
}
c_ave=(float)c_sum/(float)count;
m_ave=(float)m_sum/(float)count;
e_ave=(float)e_sum/(float)count;
clrscr();
printf("name chinese math english\n");
for(i=0;i<count;i++)
{
printf("%c %d %d %d\n",student[i].name,student[i].chn,student[i].math,student[i].eng);
}
printf("sum %d %d %d\n",c_sum,m_sum,e_sum);
printf("ave %d %d %d\n",c_ave,m_ave,e_ave);
getch();
}