Generate a tic-tac toe board with a 2-D array

Write a function that will generate a tic-tac-toe board using a 2-D array as input. Use the main() function to print out the results after the array has been rendered. You will need to use random numbers. You can determine an “X” and an “O” by using modulus arithmetic with the number 2. Assign 1 to “X” and 0 to “O”. Generate the full board. It doesn’t matter if there is more than one win on the board or not.

Getting compiler error. Any help would be appreciated.
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 <cstdlib>
#include <ctime>
using namespace std;

const int ROW = 3, COL = 3;

void ticTacToe(int board[][COL])
{
	srand(time(NULL));
	for (int i = 0; i < ROW; i++)
	{
		for (int j = 0; j < COL; j++)
		{
			int x = rand() % 2;
			board[i][j] = x;
		}
	}
}
int main()
{
	unsigned seed = time(0);
	srand(seed);

	char board[ROW][COL];

	ticTacToe(board);

	for (int i = 0; i < ROW; ++i)
	{
		for (int j = 0; j < COL; ++j)
		{




		}
		system("pause");
		return 0;
	}
}
Last edited on
Your function void ticTacToe(int board[][COL]) takes and integer of a multidimensional array. However, on line 25, char board[ROW][COL]; is a character data type of a multidimensional array. So on line 27, ticTacToe(board);, you will get a compiler error due to trying to call a function with a char data type into a function that only takes a integer data type.
Great! You're awesome!
How would I print my array on line 33?
[EDIT] I would change the lines 29- 41 like this..
From this...
1
2
3
4
5
6
7
8
9
10
11
12
13
	for (int i = 0; i < ROW; ++i)
	{
		for (int j = 0; j < COL; ++j)
		{




		}
		system("pause");
		return 0;
	}
}



To this...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	for (int i = 0; i < ROW; ++i)
	{
		for (int j = 0; j < COL; ++j)
		{

			cout << board[i][j] << "\t";


		}
		cout << endl;

	}
	system("pause");
	return 0;
}
Last edited on
if you want to get fancy you can draw ascii grid around the board to make the # looking board.
Topic archived. No new replies allowed.