Thread: SoccerPlayer Program

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    1

    SoccerPlayer Program

    This program should take the data from 11 soccer players and it should retrieve it from a file. i have to use a struct in it and I have to make the players into an array. I have figured out everything but my program is giving me an error in the main part and I am still unsure of why. If you could offer any advice that would be helpful

    Also her is some of the code but I have no idea how to use tags and this is my first time so hopefully your not too upset with my code and hopefully it is readable.

    Code:
    struct soccerPlayer
    {
        string name;
        int number, points;
    };
    void enterData(soccerPlayer player[], int, int);
    
    
    int main()
    {
        int SIZE = 11;
        enterData(&soccerPlayer player[SIZE]);
    }
    
    
    void enterData(soccerPlayer player[], ifstream &fin)
    {
        string del;
        for (int x = 0; x < SIZE; x++)
        {
            string name;
            getline(fin, name);
            player[x].name = name;
    
    
            fin >> player[x].number >> player[x].points;
            getline(fin, del);
    
    
            if(player[x].number < 0)
            {
                cout << "\nInvalid Player's Number" << endl;
                x--;
            }
            else if(player[x].points < 0)
            {
                cout << "\nInvalid Player's Points Scored" << endl;
                x--;
            }
        }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > enterData(&soccerPlayer player[SIZE]);
    You need to declare the array, then pass the array name as a parameter.

    soccerPlayer players[SIZE];
    enterData(players);




    > void enterData(soccerPlayer player[], int, int);
    > void enterData(soccerPlayer player[], ifstream &fin)
    Then you need to make the prototype, call and definition consistent with one another.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-15-2016, 03:29 PM
  2. Replies: 4
    Last Post: 12-21-2015, 07:17 AM
  3. Replies: 2
    Last Post: 09-09-2014, 02:36 PM
  4. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  5. Replies: 5
    Last Post: 08-16-2007, 11:43 PM

Tags for this Thread