error: no match for ‘operator[]’ in ‘team[i]’

I'm working on a program that takes some information about members of a team using structures then displays it. My compiler is not happy about my use of brackets, but I can't seem to figure out what the problem is. I get the above error in lines 20, 22, 24, 25, 28, 40, and 41, so obviously I've made the same mistake over and over. Here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <iomanip>
using namespace std;
struct Player
{
    char name [15];
    int jersey;
    int points;
};
void displayPlayer (Player&);
int main ()
{
    Player team;
    for (int i=0; i<=4; i++) 
    {
        cout << "Player " << i+1 << endl;
        cout << "Player's name: ";
        cin >> team[i].name;
        cout << "Player's jersey number: ";
        cin >> team[i].jersey;
        cout << "Points scored by player: ";
        cin >> team[i].points;
        while (team[i].points<0) 
        {
            cout << "Please enter valid input. ";
            cin >> team[i].points;
        }
    }
    displayPlayer (team);
    return 0;
}
void displayPlayer (Player &team)
{
    cout << right << setw(15) << "PLAYER NAME";
    cout <<setw (15) << "JERSEY # " << setw(15) << "POINTS SCORED" << endl;
    for (int i=0; i<=4; i++) 
    {
        cout << setw (15) << team[i].name;
        cout << setw (15) << team[i].jersey << setw(15) << team[i].points << endl;
    }
}

Thanks for the help!
I think you intend for an array of a given number of players of type Player. How many players are on the team?

Assuming it is 4, do this with your struct instead:
1
2
3
4
5
6
struct Player
{
    char name [15];
    int jersey;
    int points;
} team[4];


Then get rid of your declaration of team inside main() as it can be done just as well in your struct. Or define it like this if you need to limit scope:
Player team[4];

You are trying to work on your team like it is an array. Making these corrections will allow you to do so.
Last edited on
That fixed it. Thank you.
OP wrote:
team[i]


I suppose there is an 'i' in 'team'

*bah*dum*tss*
^this guy
lol
Topic archived. No new replies allowed.