是不是没加每个学生分别的总成绩导致的?
#include <stdio.h>
struct stu
{
char xm[20]; //姓名
char xh[20]; //学号
int pscj; // 平时成绩
int qmcj; //期末成绩
float zcj; //总成绩
};
int main()
{
struct stu student[4],t;
int i,f=0,j;float sum=0;
int a,s,d,g,h;a=s=d=g=h=0;
float average;
printf("Please enter student information");
printf("name\t Student id\t grades\t The final result\n");
for(i=0;i<4;i++)
scanf("%s,%s,%d,%d",student[i].xm,student[i].xh,&student[i].pscj,&student[i].qmcj);
printf("The total score of the students is\n");
for(i=0;i<4;i++)
{
student[i].zcj=student[i].pscj*0.3+student[i].qmcj*0.7;
sum+=student[i].zcj;
}
for(i=0;i<2;i++)
{
printf("% f",student[i].zcj);
}
average=sum/4.0;
for(i=0;i<4;i++)
for(j=0;j<4-i;j++)
{
if(student[j].zcj>student[j+1].zcj)
{
t=student[j];
student[j]=student[j+1];
student[j+1]=t;
}
}
for(i=0;i<4;i++)
{
printf("%s,%s,%d,%d,%f\n",student[i].xm,student[i].xh,student[i].pscj,student[i].qmcj,student[i].zcj);
}
for(i=0;i<4;i++)
{
if(student[i].zcj>=average)
{
f++;
printf("%s,%s,%d,%d,%f\n",student[i].xm,student[i].xh,student[i].pscj,student[i].qmcj,student[i].zcj);
}
}
printf("Class size%f%",(f/4)*100);
printf(" A B C D E\n");
for(i=0;i<4;i++)
{
switch(int(student[i].zcj)/4)
{
case 10:
case 9:a++;
break;
case 8:s++;
break;
case 7:d++;
break;
case 6:g++;
break;
default:h++;
}
}
printf("%2d(%.1f%%) ",a,(double)a/4*100);
printf("%2d(%.1f%%) ",s,(double)s/4*100);
printf("%2d(%.1f%%) ",d,(double)d/4*100);
printf("%2d(%.1f%%) ",g,(double)g/4*100);
printf("%2d(%.1f%%)\n",h,(double)h/4*100);
for(i=0;i<4;i++)
{
if(student[i].zcj>=0&&student[i].zcj<60)
{
printf("%s,%s,%d,%d,%f\n",student[i].xm,student[i].xh,student[i].pscj,student[i].qmcj,student[i].zcj);
}
}
}