I am once again getting confused with functions and arrays in C++.

I am trying to write a program that collects three values from a user, then displays those and does various things with them. In short, what's the problem with this line of code right here?

player = numPlayers(int[NUMPLAYERS]);

I am getting a parse error before '['. NUMPLAYERS is a const interger and numPlayers is a function that is being called.

Any help would be appreciated. Thank You!

you have to give the arran a name

player = numPlayers(int MyArray[NUMPLAYERS]);

Hmm. I tried that and I'm still getting the same error. "Parse Error before '['." Does something need to be done to the function that is being called in regards to the name given to the array? I gave that a try, and I'm not getting any errors with it, but it is a bit hard to determine if it's right since the program still won't compile since I'm getting the errors above.

bowler = bowlerNumber(int player[NUMPLAYERS]);

Heres the code that I asked about originally. I added a name to the array (I changed some names since posting this originally).

int bowlerNumber(int Player[NUMPLAYERS])
{
       int player;
       int i, bowlerNumber[NUMPLAYERS], total = 0;
       for (i = 0; i < NUMPLAYERS; i++)
           if (player < NUMPLAYERS)
              player = i;
       return player;
}

This is the function that is being called. Any ideas to why I'm getting this same parse error?

you have to give the arran a name

player = numPlayers(int MyArray[NUMPLAYERS]);

Yuuc! that is totally wrong. If you are calling the function all you have to do is put the name of the array there, not the array size

player = numPlayers(MyArray);

if (player < NUMPLAYERS)

you have to add the substript to he array

if (player[i] < NUMPLAYERS)
          {
                player[i] = i;
          }

return player;

The above will return a pointer to the array. You declared the function returns an integer. Either change the function prototype/preemble or change the return value.

Yuuc! that is totally wrong. If you are calling the function all you have to do is put the name of the array there, not the array size

player = numPlayers(MyArray);

you have to add the substript to he array

if (player[i] < NUMPLAYERS)
          {
                player[i] = i;
          }

you have to replace MyArray with the name of your array that you created in your program. I only posted an example of how to call the function, and not intended for you to just paste into your program without change.

The above will return a pointer to the array. You declared the function returns an integer. Either change the function prototype/preemble or change the return value.

I think I see! What you posted before was what the function declaration should have looked like, rather than the code that was actually used to call the function.

But... By putting in the code this way, I get that in

player = numPlayers(MyArray);

MyArray is undeclared.

The function prototype is

int bowlerNumber(int MyArray[NUMPLAYERS]);

I'm still a bit confused.

you have to replace MyArray with the name of the array you created in your program. I only posted an example of how to do it, and did not intend for you to just copy/paste it into your program without appropriate change.

you posted the function but you did not post main() or the function that calls bowlerNumber(), so I don't know the name of the array you need to pass.

Hi.. you need to declare the array first, then pass the array to numPlayers. I suggest reading resources such as Joel on Software to learn more about software development.

This article has been dead for over six months. Start a new discussion instead.