代码
#include<iostream>
using namespace std;
#define N 3
void input(struct Student *str)
{
for(int i=0;i<N;i++)
{
cin>>str[i]->num>>str[i]->name>>str[i]->score1>>str[i]->score2>>str[i]->score3;
str[i]->average=(str[i].score1+str[i].score2+str[3].score3)/3;
}
}
int max(struct Student *str)
{
int max=str[0]->average;
int k;
for(int i=1;i<3;i++)
if(str[i]->average>max)
{
max=str[i]->average;
k=i;
}
return k;
}
int main()
{
struct Student
{
int num;
char name[20];
double score1,score2,score3;
double average;
}str[N];
input(str);
int k;
k=max(str);
printf("%d %s %20d %d %d",str[k].num,str[k].name,str[k].score1,str[k].score2,str[k].score3);
return 0;
}
可以把报错的信息贴出来吗?这里str是结构体数组的头指针,在input()和max()里面就不能str[i]->score1,应该改为str[i].score1