PDA

Click to See Complete Forum and Search --> : array question


Dillinger4
Jul 30th, 2000, 08:38 PM
does any one know how i might go about doing this.
it's a simple tictactoe game but when the game board
function is called the values seem to be passed
to the first element of the array. so if this is
my game board -> _|_|_ only the first space on the
_|_|_
| |
game board is always updated.

int main(int argc, char* argv[])
{
cout << "Player 1 enter your cordinates:
cin >> tictactoe[x1][y1];
gameboard();

return 0;
}

void gameboard()
{



cout << endl;
cout << setw(5) << tictactoe[0][0] << setw(4) << tictactoe[0][1] << setw(4) << tictactoe[0][2] << endl;
}

HarryW
Jul 31st, 2000, 04:19 AM
When you refer to the array tictactoe[] in the function gameboard(), the array is not in scope. If you want to be able to access the array outside of the function it was declared in, you must declare it at a higher-leve scope (in this case global scope) or pass the array as an argument.

Try:


int main(int argc, char* argv[])
{ char* tictactoe[3][3]
int x1, y1
cout << "Player 1 enter your cordinates:
cin >> x1 >> y1;
gameboard(tictactoe[x1][y1]);

return 0;
}

void gameboard(char* tictactoe[3][3])
{ cout << endl;
cout << setw(5) << tictactoe[0][0]
<< setw(4) << tictactoe[0][1]
<< setw(4) << tictactoe[0][2]
<< endl;
}



or something along those lines.

I'm not quite sure how that code works with the rest of your program. If that's your whole program then maybe youought to rethink the structure of it.