结构体,函数疑惑,我老师和我已跪
结构体录入5位同学,4门成绩。功能函数求各门功课的平均分。
主要问题:无法得到平均分。如图所示。跪求论坛上的各位大神详细解答!
struct score
{
int eng,math,geo,cmp,CAD;
};
struct st
{
char xm[8];
struct score fs;
}a[5]={{"CW",55,82,84,87,45},{"HZF",80,82,95,89,90},{"JWY",78,45,80,97,86},{"LZY",87,88,90,91,92},{"LJJ",89,71,90,67,59}};
float *ave()
{
int i;
float aveger[5],sum[5];
float *aver;
aver=aveger;
for (i=0;i<5;i++)
{
sum[0]+=a[i].fs.eng;// printf("%.1f ",sum[0]);
sum[1]+=a[i].fs.math;
sum[2]+=a[i].fs.geo;
sum[3]+=a[i].fs.cmp;
sum[4]+=a[i].fs.CAD;
}
// printf("%.1f\n",sum[0]);
aveger[0]=sum[0]/5; //printf("\n%.1f ",aveger[0]);
//printf("%.1f\n",aveger[0]);
aveger[1]=sum[1]/5;
aveger[2]=sum[2]/5;
aveger[3]=sum[3]/5;
aveger[4]=sum[4]/5;
//printf("%p",aveger);
return aver;
}
int main()
{int i,n=1;char c;float *p;
//printf("%p\n",a);
printf("name ________________score________________\n eng math geo cmp CAD\n");
for(i=0;i<5;i++)
{printf("%-4s",a[i].xm);
printf(" %-5d",a[i].fs.eng);
printf("%-6d",a[i].fs.math);
printf("%-5d",a[i].fs.geo);
printf("%-4d",a[i].fs.cmp);
printf("%-3d",a[i].fs.CAD);
printf("\n");
}
printf("------------------------------------------------------------------------\n");
p=ave();
for(i=0;i<5;i++)
{
printf("%.1f ",*p);p++;
}