Hey I am trying to do a tic tac to game, and im getting a few errors that I don't understand, Please help me.
Here is my code:
#include<iostream>
using namespace std;
const int num_rows = 3;
const int num_colm = 3;
void xPlayer(char board[][num_colm], int);
void oPlayer(char board[][num_colm], int);
bool checkBoardX(char board[][num_colm], int);
bool checkBoardO(char board[][num_colm], int);
int main()
{
int X;
int O;
char board[num_rows][num_colm] = {{1,2,3},{4,5,6},{7,8,9}};
for(int i=0; i < 3; i++)
{
cout << endl;
for(int j=0; j<3; j++)
cout << board[i][j];
}
do
{
xPlayer(board, num_rows);
if(!checkBoardX(board, num_rows))
oPlayer(board, num_rows);
}
while (checkBoardX(board, num_rows)||checkBoardO(board, num_rows));
if(checkBoardX(board, num_rows))
cout << "Player X wins" <<endl;
else
cout << "Player O wins" <<endl;
return 0;
}
void xPlayer(char board[][num_colm], int num_rows)
{
int move;
cout << "Player X, please make your move (1-9): ";
for(int i = 0; i < 3; i++)
{
cout << endl;
for(int j = 0; j < num_rows; j++)
cout << board[i][j];
}
cin >> move;
switch(move)
{
case 1: board[0][0] = 'X';
break;
case 2: board[0][1] = 'X';
break;
case 3: board[0][2] = 'X';
break;
case 4: board[1][0] = 'X';
break;
case 5: board[1][1] = 'X';
break;
case 6: board[1][2] = 'X';
break;
case 7: board[2][0] = 'X';
break;
case 8: board[2][1] = 'X';
break;
case 9: board[2][2] = 'X';
break;
}
return;
}
void oPlayer(char board[][num_colm], int num_rows)
{
int move;
cout << "Player X, please make your move (1-9): ";
for(int i = 0; i < 3; i++)
{
cout << endl;
for(int j = 0; j < num_rows; j++)
cout << board[i][j];
}
cin >> move;
switch(move)
{
case 1: board[0][0] = 'O';
break;
case 2: board[0][1] = 'O';
break;
case 3: board[0][2] = 'O';
break;
case 4: board[1][0] = 'O';
break;
case 5: board[1][1] = 'O';
break;
case 6: board[1][2] = 'O';
break;
case 7: board[2][0] = 'O';
break;
case 8: board[2][1] = 'O';
break;
case 9: board[2][2] = 'O';
break;
}
return;
}
bool checkboardX(char board[][num_colm], int num_rows)
{
if(board[0][0] == board[0][1] && board[0][2] == board[0][1])
return true;
if(board[1][0] == board[1][1] && board[1][2] == board[1][1])
return true;
if(board[2][0] == board[2][1] && board[2][2] == board[2][1])
return true;
if(board[0][0] == board[1][0] && board[2][0] == board[1][0])
return true;
if(board[0][1] == board[1][1] && board[2][1] == board[1][1])
return true;
if(board[0][2] == board[1][2] && board[2][2] == board[1][2])
return true;
if(board[0][0] == board[1][1] && board[2][2] == board[1][1])
return true;
if(board[2][0] == board[1][1] && board[0][2] == board[1][1])
return true;
else
return false;
}
bool checkboardO(char board[][num_colm], int num_rows)
{
if(board[0][0] == board[0][1] && board[0][2] == board[0][1])
return true;
if(board[1][0] == board[1][1] && board[1][2] == board[1][1])
return true;
if(board[2][0] == board[2][1] && board[2][2] == board[2][1])
return true;
if(board[0][0] == board[1][0] && board[2][0] == board[1][0])
return true;
if(board[0][1] == board[1][1] && board[2][1] == board[1][1])
return true;
if(board[0][2] == board[1][2] && board[2][2] == board[1][2])
return true;
if(board[0][0] == board[1][1] && board[2][2] == board[1][1])
return true;
if(board[2][0] == board[1][1] && board[0][2] == board[1][1])
return true;
else
return false;
}
When I compile it this is what I get as my errors.
Undefined first referenced
symbol in file
checkBoardX(char (*) [3], int) /var/tmp//ccLH9ocm.o
checkBoardO(char (*) [3], int) /var/tmp//ccLH9ocm.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Thanks for the help.