c语言错误,怎么改????急
nooperatordefinedwhichtakesaright-handoperandoftype'float'(orthereisnoacceptableconve...
no operator defined which takes a right-hand operand of type 'float' (or there is no acceptable conversion)
#include<stdio.h>
struct student
{int num;
char name[20];
float score[3];
float ave;
};
void main()
{
struct student stu[5],m,*p;
float a;
void input(struct student *p,int n);
float average(struct student *p,int n);
float max(struct student s[],int n);
p=stu;
input(p,5);
a=average(p,5);
m=max(stu,5);
printf("总平均分为%f",a);
printf("成绩最高学生信息如下:\n");
printf("%d,%s",m.num,m.name);
printf("%.1f,%.1f,%.1f,%.1f",m.scor[0],m.score[1],m.score[2],m.ave);
}
void input(struct student *p,int n)
{int i,j;
for(i=0;i<p;i++,p++)
{
printf("\ninput the student's number,name and score:");
printf("\nNuber:");scanf("%d",&p->num);
printf("Name:");scanf("%s",p->name);
for(j=0;j<3;j++)
{
printf("Score[%d]:",j);
scanf("%f",&p->score[j]);
}
}
float average(struct student *p,int n)
{
int i,j;
float sum1,sum2;
sum2=0;
for(i=0;i<n;i++)
{
sum1=0;
for(j=0;j<3;j++)
{
sum1=sum1+p->score[j];
}
p->ave=sum1/3;
sum2=sum2+sum1;
}
ave=sum2/(n*3);
return ave;
}
float max(struct student s[],int n)
{
int i,j;
struct student k;
k=s[0];
for(i=0;i<n;i++)
{
if(k.ave<s[i].ave)
k=s[i];
}
return k;
} 展开
#include<stdio.h>
struct student
{int num;
char name[20];
float score[3];
float ave;
};
void main()
{
struct student stu[5],m,*p;
float a;
void input(struct student *p,int n);
float average(struct student *p,int n);
float max(struct student s[],int n);
p=stu;
input(p,5);
a=average(p,5);
m=max(stu,5);
printf("总平均分为%f",a);
printf("成绩最高学生信息如下:\n");
printf("%d,%s",m.num,m.name);
printf("%.1f,%.1f,%.1f,%.1f",m.scor[0],m.score[1],m.score[2],m.ave);
}
void input(struct student *p,int n)
{int i,j;
for(i=0;i<p;i++,p++)
{
printf("\ninput the student's number,name and score:");
printf("\nNuber:");scanf("%d",&p->num);
printf("Name:");scanf("%s",p->name);
for(j=0;j<3;j++)
{
printf("Score[%d]:",j);
scanf("%f",&p->score[j]);
}
}
float average(struct student *p,int n)
{
int i,j;
float sum1,sum2;
sum2=0;
for(i=0;i<n;i++)
{
sum1=0;
for(j=0;j<3;j++)
{
sum1=sum1+p->score[j];
}
p->ave=sum1/3;
sum2=sum2+sum1;
}
ave=sum2/(n*3);
return ave;
}
float max(struct student s[],int n)
{
int i,j;
struct student k;
k=s[0];
for(i=0;i<n;i++)
{
if(k.ave<s[i].ave)
k=s[i];
}
return k;
} 展开
3个回答
展开全部
#include<stdio.h> void input(struct student *p,int n);
float aver(struct student *p,int n);
struct student max(struct student s[],int n);
struct student
{int num;
char name[20];
float score[3];
float ave;
};
void main()
{
struct student stu[5],m,*p;
float a;
p=stu;
input(p,5);
a=aver(p,5);
m=max(stu,5);
printf("总平均分为%f",a);
printf("成绩最高学生信息如下:\n");
printf("%d,%s",m.num,m.name);
printf("%.1f,%.1f,%.1f,%.1f",m.score[0],m.score[1],m.score[2],m.ave);
}
void input(struct student *p,int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("input the student's number,name and score:\n");
printf("Nuber:\n");
scanf("%d",&(p+i)->num);
printf("Name:");
scanf("%s",(p+i)->name);
printf("输入各科成绩\n");
for(j=0;j<3;j++)
{
scanf("%f",&p->score[j]);
}
}
}
float aver(struct student *p,int n)
{
float ave=0.0;
for(int i=0;i<n;++i)
{
(p+i)->ave=((p+i)->score[0]+(p+i)->score[1]+(p+i)->score[2])/3;
ave+=(p+i)->ave;
}
ave=ave/n;
return ave;
}
struct student max(struct student s[],int n)
{
int i;
student stuTemp;
stuTemp=s[0];
for(i=0;i<n;i++)
{
if(stuTemp.ave<s[i].ave)
stuTemp=s[i];
}
return stuTemp;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <math.h>
struct student
{
int num;
char name[20];
float score[3];
float ave;
};
void input(student *p,int n)
{
int i,j;
for(i=0;i<n;i++,p++)
{
printf("\ninput the student's number,name and score:");
printf("\nNuber:");scanf("%d",&p->num);
printf("Name:");scanf("%s",p->name);
for(j=0;j<3;j++)
{
printf("Score[%d]:",j);
scanf("%f",&p->score[j]);
}
}
};
float average(student *p,int n)
{
int i,j;
float sum1,sum2,ave;
sum2=0;
for(i=0;i<n;i++)
{
sum1=0;
for(j=0;j<3;j++)
{
sum1=sum1+p->score[j];
}
p->ave=sum1/3;
sum2=sum2+sum1;
}
ave=sum2/(n*3);
return ave;
};
student max(student s[],int n)
{
int i,j;
student k;
k=s[0];
for(i=0;i<n;i++)
{
if(k.ave<s[i].ave)
k=s[i];
}
return k;
};
void main()
{
student stu[5],m,*p;
float a;
p=stu;
input(p,5);
a=average(p,5);
m=max(stu,5);
printf("总平均分为%f",a);
printf("成绩最高学生信息如下:\n");
printf("%d,%s",m.num,m.name);
printf("%.1f,%.1f,%.1f,%.1f",m.score[0],m.score[1],m.score[2],m.ave);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误太多,自己再调试
编译器难道不会报错??
这么多输入错误,好多你都敲 错了
自己逐行看啊
score你敲成scor
ave没定义都敢用,至少得有个xxxx.ave吧
编译器难道不会报错??
这么多输入错误,好多你都敲 错了
自己逐行看啊
score你敲成scor
ave没定义都敢用,至少得有个xxxx.ave吧
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询