关于结构体的一道题
来源:百度知道 编辑:UC知道 时间:2024/05/18 09:25:30
#include <stdio.h>
struct student
{
int scorech,scorema,scoreen;
};
void main()
{
int stu[5];
int i,sum,minch,minma,minen;
printf("请输入第1个学生的语数外成绩是:\n");
scanf("%d%d%d\n",&stu.scorech,&stu.scorema,&stu.scoreen);
}
错误 3 error C2228: left of '.scoreen' must have class/struct/union c:\documents and settings\arlone\桌面\nm\nm\nm.cpp 12
总是会出现这样的错误 原因何在?
struct student
{
int scorech,scorema,scoreen;
};
void main()
{
int stu[5];
int i,sum,minch,minma,minen;
printf("请输入第1个学生的语数外成绩是:\n");
scanf("%d%d%d\n",&stu.scorech,&stu.scorema,&stu.scoreen);
}
错误 3 error C2228: left of '.scoreen' must have class/struct/union c:\documents and settings\arlone\桌面\nm\nm\nm.cpp 12
总是会出现这样的错误 原因何在?
int stu[5]; 改成
struct student stu[5];
,&stu.scorech,&stu.scorema,&stu.scoreen
改成 &stu[0].scorech ....。。。。
nclude<iostream.h>
struct student
{
int ch_score;
int ma_score;
int en_score;
};
void stuscore(student &p);
void print(student &p);
void main()
{
struct student stu[5];
int i;
for(i=0; i<5; i++)
{
stuscore(stu[i]);
print(stu[i]);
}
}
void stuscore(student &p)
{
cout<<"please enter score for one student:"<<endl;
cin>>p.ch_score>>p.ma_score>>p.en_score;
}
void print(student &p)
{
cout<<p.ch_score<<" "
<<p.ma_score<<" "
<<p.en_score<&