What's wrong?(Tic Tac Toe exercise)

What's wrong at the begginig of my code? it output TicTacToe and but dont output the Game Board
Please help me
Thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()
{
	cout << "TicTacToe\n";
	int Game_Board [3][3] =
	{
		{ 0, 1, 2 },
		{ 3, 4, 5 },
		{ 6, 7, 8 }
	};
	cout << Game_Board;
	getchar();
	return 0;
}

SkyDriver2500
afaik, cout doesn't have an operator<< overload for multi dimension arrays. You need to make your own loop to output it.

something like this will accomplish what I believe you're trying to do.
1
2
3
4
5
6
7
8
for(int x = 0; x < 3; ++x)
{
    for(int y = 0; i < 3; ++y)
    {
        cout << Game_Board[y][x];
    }
    cout << endl;
}
Last edited on
i didn't modify the code already but it seems that it is the GameBoard i want, i want a GameBoard with numbers to make the game simple to create and play. How do i make a array to output:

1 2 3
4 5 6
7 8 9
?
Forget what i said
Is this code correct or it's possible?
1
2
3
4
	unsigned Player_Play,Computer_Play;
	srand(Computer_Play*(time(0)));
	Computer_Play=rand()%9;
	Player_Play!=Computer_Play;
You could do this,
1
2
3
	unsigned Player_Play, Computer_Play;
	srand(time(0));
	Computer_Play = rand()%9;


The other line, Player_Play!=Computer_Play; has no effect, it's just a passive expression which will be evaluated, then ignored.
Then how i tell the program that the Computer_Play have to be diferent than Player_Play?
There are two separate concepts
1. assign a particular value to the variable
2. test whether the value is acceptable

Presumably the player input comes from the keyboard, so you might do:
1
2
cout << "enter your move, 1 - 9 : ";
cin >>Player_Play;


Then you could test it
1
2
if (Player_Play == Computer_Play)
    cout << "invalid move" << endl;


But of course the actual game is rather different to this, as you need to check that the attempted move doesn't use any of the nine squares which are already occupied.
Topic archived. No new replies allowed.