Tic Tac Toe

Hello! I am trying to create a tic tac toe game. I am receiving an error in both check player functions. The error message is "lvalue required as left operand assignment," not sure how to solve this so some help would be appreciated. Also, I know my code is majorly flawed, so any help on how to improve it would be awesome. Thank you!





#include <iostream>

using namespace std;

const int row = 3;
const int column = 3;
const int size = 9;

bool checkPlayer_x();
bool checkPlayer_o();
int xInput();
int oInput();


char board[row][column] = {
{'*', '*', '*'},
{ '*', '*', '*'},
{'*', '*', '*'},
};

int main()
{
//display board
for ( int x = 0; x < row; x++)
{
for(int y = 0; y < column; y++)
{
cout << "Tic Tac Toe\n";
cout << board[x][y];
}
}

if(checkPlayer_x() == 1)
{
cout << "Player X wins!";
}
else if (checkPlayer_o() == 1)
{
cout << "Player O wins!";
}
else
{
cout << "Next player. \n";
}
}

int xInput()
{
cout << "Player X moves first." << endl;

int x, y;

cout << "Rows are labeled 1-3 and columns are labeled 1-3.\n";
cout << "Enter the number for the row first then column. \n";
cout << "Player X enter coordinates to make a move: ";
cin >> x >> y;

board[x][y];
//place x at this value

}

int oInput()
{
cout << "Player X moves first." << endl;

int x, y;

cout << "Rows are labeled 1-3 and columns are labeled 1-3.\n";
cout << "Enter the number for the row first then column. \n";
cout << "Player X enter coordinates to make a move: ";
cin >> x >> y;

// convergence to index
board[x][y];
//place x at this value
}

bool checkPlayer_x()
{

if(board[0][0] = 'X' && board[0][1] = 'X' && board[0][2] = 'X')
{return 1;}
if(board[1][0] = 'X' && board[1][1] = 'X' && board[1][2] = 'X')
{return 1; }
if(board[2][0] = 'X' && board[2][1] = 'X' && board[2][2] = 'X')
{return 1;}
if(board[0][0] = 'X' && board[1][1] = 'X' && board[2][2] = 'X')
{return 1;}
if(board[0][0] = 'X' && board[1][0] = 'X' && board[2][0] = 'X')
{return 1;}
if(board[0][1] = 'X' && board[1][1] = 'X' && board[2][1] = 'X')
{return 1;}
if(board[0][2] = 'X' && board[1][2] = 'X' && board[2][2] = 'X')
{return 1;}
if(board[0][2] = 'X' && board[1][1] = 'X' && board[2][1] = 'X')
{return 1;}

else
{
return 0;
}
}

bool checkPlayer_o()
{
if(board[0][0] = 'X' && board[0][1] = 'X' && board[0][2] = 'X')
{return 1;}
if(board[1][0] = 'X' && board[1][1] = 'X' && board[1][2] = 'X')
{return 1;}
if(board[2][0] = 'X' && board[2][1] = 'X' && board[2][2] = 'X')
{return 1;}
if(board[0][0] = 'X' && board[1][1] = 'X' && board[2][2] = 'X')
{return 1;}
if(board[0][0] = 'X' && board[1][0] = 'X' && board[2][0] = 'X')
{return 1;}
if(board[0][1] = 'X' && board[1][1] = 'X' && board[2][1] = 'X')
{return 1;}
if(board[0][2] = 'X' && board[1][2] = 'X' && board[2][2] = 'X')
{return 1;}
if(board[0][2] = 'X' && board[1][1] = 'X' && board[2][1] = 'X')
{return 1;}
else
{
return 0;
}
}
}
if(board[0][0] = 'X' && board[0][1] = 'X' && board[0][2] = 'X')

should be

if(board[0][0] == 'X' && board[0][1] == 'X' && board[0][2] == 'X')

and repeat...

Happy to help.
Last edited on
@programmingisLife
this is a classic mistake = vs ==
== is an operator of comparison
= is an operator of assignment
Topic archived. No new replies allowed.