#include
using namespace std;
#include
#include
struct Student
{
string name;
int score;
};
struct Teacher
{
string tname;
struct Student arr[5];
};
void read(struct Teacher tarry[])
{
srand((unsigned int)time(NULL));
string nameseed="ABCDE";
for(int i;i<3;i++)
{
tarry[i].tname="teacher_";
tarry[i].tname+=nameseed[i];
for(int j;j<5;j++)
{
tarry[i].arr[j].name="student_";
tarry[i].arr[j].name+=nameseed[j];
tarry[i].arr[j].score=rand()%41+60;
}
}
}
void print(struct Teacher tarry[])
{
for(int n;n<3;n++)
{
cout<<"辅导员:"<
for(int m;m<5;m++)
{
cout<<"学生姓名:"<
<
}
}
}
int main()
{
struct Teacher tarry[3];
int len=3;
read(tarry);
print(tarry);
system("pause");
}
for(int n;n<3;n++)
你所有的for语句,第一项都没有写初始值啊
要改成 for(int n=0;n<3;n++)这样子,所有for循环都是这个问题
供参考:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
struct Student
{
string name;
int score;
};
struct Teacher
{
string tname;
struct Student arr[5];
};
void read(struct Teacher tarry[])
{
srand((unsigned int)time(NULL));
string nameseed = "ABCDE";
for (int i = 0; i < 3; i++) //for (int i; i < 3; i++)
{
tarry[i].tname = "teacher_";
tarry[i].tname += nameseed[i];
for (int j = 0; j < 5; j++) //for (int j; j < 5; j++)
{
tarry[i].arr[j].name = "student_";
tarry[i].arr[j].name += nameseed[j];
tarry[i].arr[j].score = rand() % 41 + 60;
}
}
}
void print(struct Teacher tarry[])
{
for (int n = 0; n < 3; n++) //for (int n; n < 3; n++)
{
cout << "辅导员:" << tarry[n].tname << endl;
for (int m = 0; m < 5; m++) //for (int m; m < 5; m++)
{
cout << "学生姓名:" << tarry[n].arr[m].name
<< " 成绩:" << tarry[n].arr[m].score << endl;
}
}
}
int main()
{
struct Teacher tarry[3];
int len = 3;
read(tarry);
print(tarry);
//system("pause");
return 0;
}