各位帮我看下,为什么这个程序只能输入学号和姓名,不能输入成绩。
#include<stdio.h>#define n 10
struct student
{char num[6];
char name[8];
float score[4];
float avr;
}stu[n];
void main()
{int i,j,maxi;
char x;
float sum, max,average;
for(i=0;i<n;i++)
{printf("input score of student %d:\n",i+1);
printf("no.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(i=0;i<n;i++)
{sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].avr=sum/3.0;
average+=stu[i].avr;
if(sum>max)
{max=sum;
maxi=i;
}
}
average/=n;
x=getchar();
printf("x=%c",x);
if(x='D')
{printf("no. name score1 score2 score3 average\n");
for(i=0;i<n;i++)
{printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9.2f",stu[i].score[j]);
printf(" %8.2f\n",stu[i].avr);}}
if(x='B')
{printf("average=%5.2f\n",average);}
if(x='C')
{printf("the highest score is:student%s,%s.\n",stu[i].num,stu[i].name);
printf("his score are: %6.2f,%6.2f,%6.2f,avreage: %5.2f.\n",stu[maxi].score[0],
stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);}
}
[[it] 本帖最后由 wxmlianying 于 2008-12-10 10:44 编辑 [/it]]