问题遇到的现象和发生背景
运行中断但并没有报错
问题相关代码,请勿粘贴截图
#include<iostream>
using namespace std;
struct Student
{
int Sname;
int score;
};
struct Teacher
{
string Tname;
struct Student stu[5];
};
void allocatespace1(struct Teacher tArray[])
{
string nameseed = "ABCDE";
for (int i = 0; i < 3; i++)
{
tArray[i].Tname = "Teacher_";
tArray[i].Tname += nameseed[i];
for (int j = 1; j < 6; j++)
{
tArray[i].stu[j].Sname =j;
tArray[i].stu[j].score = rand() % 100 + 1;
}
}
}
int main()
{
struct Teacher tArray[3];
allocatespace1(tArray);
for (int k = 0; k < 3; k++)
{
cout << "teacher name:" << tArray[k].Tname << endl;
for (int m = 1; m < 6; m++)
{
cout << "student name:" << tArray[k].stu[m].Sname << endl;
cout << "student score:" << tArray[k].stu[m].score << endl;
}
}
system("pause");
return 0;
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
让每个教师的第五名学生的成绩为正常范围