Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include const int SIZE = 3 ; void initialize ( char board [ SIZE ] [ SIZE ] , int record [ 2
#include
#include
#include
const int SIZE ;
void initializechar boardSIZESIZE int record
for int i ; i SIZE; i
for int j ; j SIZE; j
boardij;
for int i ; i ; i
for int j ; j ; j
recordij;
void drawBoardchar boardSIZESIZE
systemcls; You might need to change this for other platforms
std::cout
;
for int i ; i SIZE; i
std::cout ;
for int j ; j SIZE; j
std::cout boardij;
std::cout
;
bool checkWinchar boardSIZESIZE char player
for int i ; i SIZE; i
if boardi player && boardi player && boardi player
boardi player && boardi player && boardi player
return true;
if board player && board player && board player
board player && board player && board player
return true;
return false;
void computerTurnchar boardSIZESIZE
int row, col;
do
row rand SIZE;
col rand SIZE;
while boardrowcol;
boardrowcolO;
int main
char boardSIZESIZE;
int record;
int userWins ;
int computerWins ;
int gamesToPlay;
std::cout "Enter the number of games you want to play: ;
std::cin gamesToPlay;
srandstaticcasttime;
for int game ; game gamesToPlay; game
initializeboard record;
std::cout "Welcome to TicTacToe Game game
;
for int turn ; turn SIZE SIZE; turn
drawBoardboard;
if turn
int row, col;
std::cout "Your turn X enter row and column : ;
std::cin row col;
row;
col;
if row row SIZE col col SIZE boardrowcol
std::cout "Invalid move. Try again.
;
turn; Repeat the same turn
continue;
boardrowcolX;
if checkWinboardX
drawBoardboard;
std::cout "You win!
;
userWins;
break;
else
std::cout "Computer's turn O:
;
computerTurnboard;
if checkWinboardO
drawBoardboard;
std::cout "Computer wins!
;
computerWins;
break;
End of the game
drawBoardboard;
if checkWinboardX && checkWinboardO
std::cout "It's a draw!
;
std::cout "Overall Winner: userWins computerWins "You" : "Computer" with
userWins computerWins userWins : computerWins wins.
;
std::cout "Number of user wins: userWins
;
std::cout "Number of computer wins: computerWins
;
return ;
what is wrong with my code? it doesnot shows the board properly please review it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started