c语言问题,要求定义一个结构体涵盖学生姓名成绩等,再编写输入,求总成绩,输出的函数。哪里错了?

2025-04-17 00:01:25
推荐回答(2个)
回答1:

看不太清楚,最好用电脑把代码发上来

 

你的结构体定义声明有问题:

把结构体改为

struct student
{
   float No;
   char Name[100];//改成字符型数组
   int b[3];
   int Sum;
}

回答2:

按你的思路修改了一下,对比一下错误原因吧!
struct student
{
char no[9];
char name[20];
float h[4];
float sum;
};
void input(struct student *a)
{
cout << "请输入学生学号和姓名" << endl;
cin >> a->no >> a->name;
cout << "请依次输入学生的数学 物理 数据结构成绩" << endl;
cin >> a->h[0] >> a->h[1]>> a->h[2];
}
void sumscore(struct student *a)
{
a->sum = a->h[0] + a->h[1] + a->h[2];
}

void show(const struct student *a)
{
cout << "该学生成绩为:" << a->h[0]<< “ ”<< a->h[1] << “ ”<< a->h[2]< cout << "该学生总成绩为:" << a->sum << endl;
}
int main()
{
struct student a;
input(&a);
sumscore(&a);
show(&a);
return 0;
}