Quick Tic Tac Toe Question

I have a quick question in regards to a program tic tac toe. How can I display Game over! when all the spots are taken. I'm not good with arrays yet and would like to know thanks in advance.
P.S. I don't need to display who won or whatever I only need a game over

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
using namespace std;

void display(int & table);
void input(int & num);
void Toggleplayer();


char player = 'X';

char Tak[3][3] = { '1','2','3','4','5','6','7','8','9' };//char Tak so that X's and O's appear and makes sure they are compatible with eachother

int main()
{
	int table, num;
	while (1)
	{
		display(table);
		input(num);
		Toggleplayer();
		
	}
}


void display(int & table)
{
	
	for (int row = 0;row < 3;++row)
	{
		for (int col = 0;col < 3;++col)
		{
			cout << Tak[row][col] << " ";//do not use endl; here (double quotes helps put them horizantally)
		}
		cout << endl;//needed to make sure that each row has their own line
	}
	
}


void input(int & num)
{

	cout << "Enter in a number you want to occupy" << endl;
	cin >> num;
	
	if (num == 1)
	{
		Tak[0][0] = player;
	}
	else if (num == 2)
	{
		Tak[0][1] = player;
	}
	else if (num == 3)
	{
		Tak[0][2] = player;
	}
	else if (num == 4)
	{
		Tak[1][0] = player;
	}
	else if (num == 5)
	{
		Tak[1][1] = player;
	}
	else if (num == 6)
	{
		Tak[1][2] = player;
	}
	else if (num == 7)
	{
		Tak[2][0] = player;
	}
	else if (num == 8)
	{
		Tak[2][1] = player;
	}
	else if (num == 9)
	{
		Tak[2][2] = player;
	}
}

void Toggleplayer()
{
	if (player == 'X')
	{
		player = 'O';
	}
	else
	{
		player = 'X';
	}
}
Last edited on
How can I display Game over!
cout << "Game over!";
I guess you want to know how to detect if there is no further free field on a TTT-board, am I right?

1
2
3
4
5
6
7
8
9
10
11
12
13
char Tak[3][3] = { {'1','2','3'}
                  ,{'4','5','6'}
                  ,{'7','8','9'} }; 

bool isDraw( char Tak[3][3] )
{
    for (int row = 0; row < 3; ++row)
        for (int col = 0; col < 3; ++col)
            if (Tak[row][col] != 'X' && Tak[row][col] != 'O')
                return false;
    
    return true;
}
Count up to 9.
char* tak2 = tak[0]; //collapse the board to 1-d
for(i = 0; i < 9; i++)
if (tak2[i] == *what?*) then its empty ... or add up to 9, or whatever logic.
Topic archived. No new replies allowed.