C++程序错误,实在是不知道哪里有错。
#include<iostream>using namespace std;
#include<cstring>
struct student
{
int num;
char name[20];
float score[3];
float avg_score;
student *next;
}stu[100],*p;
void print(student *p)
{
cout<<"学生"<<p->name<<"的学号为"<<p->num;
p->avg_score=(p->score[0]+p->score[1]+p->score[2])/3;
cout<<"语文成绩是: "<<p-score[0]<<"shuxue"<<p-score[1]<<"yingyv"<<p->score[2]<<"平均分"<<p->avg_score;
}
int main (void)
{
int stu_num;
cout<<"请输入同学数目:";
cin>>stu_num;
for(int i=0;i<stu_num;i++)
{
cout<<"请输入学生"<<i+1<<"的信息:"<<endl<<"xuehao :";
cin>>stu[i].num;
cout<<"姓名:";
cin>>stu[i].name;
cout<<"语文分数:";
cin>>stu[i].score[0];
cout<<"数学分数: ";
cin>>stu[i].score[1];
cout<<"英语分数:";
cin>>stu[i].score[2];
cout<<endl<<endl;
}
for(int i=0;i<stu_num;i++)
stu[i].next=&stu[i+1];
stu[stu_num-1].next=NULL;
p=&stu[0];
do{
print(p);
p=p->next;
}while(p!=NULL);
return 0;
}
1\源.cpp(16): error C2065: “score”: 未声明的标识符
出现这样的错误,没有声明标识符吗?
好生奇怪。