【发布时间】:2021-03-17 01:20:30
【问题描述】:
我有很多这样的代码:
struct SoccerTeam
{
string teamName;
int totalGame;
SoccerPlayer playerStore[PLAYERS] = { { "NONE", 0 }, { "NONE", 0 }, { "NONE", 0 }, { "NONE", 0 }, { "NONE", 0 } };
};
//Function prototypes.
void showStats(SoccerTeam team[], bool);
void getTeamInfo(SoccerTeam team[]);
//Main function.
int main()
{
bool flag = true;
SoccerTeam leagueTeam[TEAM] = { { "NONE", 0, "NONE"}, { "NONE", 0, "NONE"}, { "NONE", 0, "NONE"}, { "NONE", 0, "NONE"} };
//Call the function to print out the content of the initialized array.
showStats(leagueTeam, flag);
//Call the function to ask the user to enter values into the array.
getTeamInfo(leagueTeam);
//Call the show stat function again with user's input.
showStats(leagueTeam, flag);
}
我正在尝试使用以下函数将初始化的数组显示到屏幕上:
//Function that displays the contents of the array to the screen.
void showStats(SoccerTeam team[], bool flag)
{
double averageG = 0.00;
cout << "Data After Initialization:" << endl << endl;
for (int i = 0; i < TEAM; i++)
{
cout << "The team: " << team[i].teamName << " has played " << team[i].totalGame << " games." << endl;
for (int j = 0; j < PLAYERS; j++)
{
cout << right << setw(20) << "Player: " << team[j].playerStore->playerName << " has " << team[j].playerStore->goalScore << " goals. " << endl;
averageG = team[j].playerStore->goalScore / team[j].totalGame;
cout << "The average goals are: " << averageG << endl;
}
}
}
而且输出只显示第一行和第三行。我不知道它有什么问题。我是结构新手,但我很难理解这一点:
【问题讨论】: