0

I have a bulk of code like this:

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);
}

And I'm trying to display the initialized array to the screen, by using the function:

//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;
        }
    }
}

And the output only shows the first and third line. I don't know what's wrong with it. I'm new to structure and yet I have a hard time understanding this:

enter image description here

1 Answer 1

1

Your error code clearly indicates:

0xc0000094 Integer divide by zero exception

Coming from this line:

averageG = team[j].playerStore->goalScore / team[j].totalGame;

Also, this doesn't look right:

SoccerTeam leagueTeam[TEAM] = { { "NONE", 0, "NONE"}, { "NONE", 0, "NONE"}, { "NONE", 0, "NONE"}, { "NONE", 0, "NONE"} };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.