Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Why wont this code compile on gradscope? #include #include #define SIZE 3 #define EMPTY ' ' char board [ SIZE ] [ SIZE ] ;
Why wont this code compile on gradscope?
#include
#include
#define SIZE
#define EMPTY
char boardSIZESIZE;
const char PLAYERX X;
const char PLAYERO O;
void resetBoard;
void printBoard;
int checkFreeSpaces;
void playerMovechar player;
char checkWinner;
void printWinnerchar winner;
int main
char winner EMPTY;
char currentPlayer PLAYERX;
resetBoard;
while winner EMPTY && checkFreeSpaces
printBoard;
if currentPlayer PLAYERX
printfXs turn ;
else
printfOs turn ;
playerMovecurrentPlayer;
winner checkWinner;
currentPlayer currentPlayer PLAYERX PLAYERO : PLAYERX;
printBoard;
printWinnerwinner;
return ;
void resetBoard
for int i ; i SIZE; i
for int j ; j SIZE; j
boardij EMPTY;
void printBoard
for int i ; i SIZE; i
for int j ; j SIZE; j
printfc boardij;
if j SIZE printf;
printf
;
if i SIZE printf
;
int checkFreeSpaces
int freeSpaces SIZE SIZE;
for int i ; i SIZE; i
for int j ; j SIZE; j
if boardij EMPTY
freeSpaces;
return freeSpaces;
void playerMovechar player
int x y;
while
if scanfd d &x &y
fprintfstderr "Need coordinates
;
while getchar
; clear the input buffer
continue;
if x x y y
fprintfstderrdd is not a valid square; the numbers must be between and inclusive
x y;
continue;
x; y; adjust for indexed array
if boardxy EMPTY
fprintfstderrc has played dd
boardxy x y ;
continue;
boardxy player;
break;
char checkWinner
Check rows and columns
for int i ; i SIZE; i
if boardi EMPTY && boardi boardi && boardi boardi return boardi;
if boardi EMPTY && boardi boardi && boardi boardi return boardi;
Check diagonals
if board EMPTY && board board && board board return board;
if board EMPTY && board board && board board return board;
return EMPTY;
void printWinnerchar winner
if winner PLAYERX
printfX wins!
;
else if winner PLAYERO
printfO wins!
;
else
printfIts a tie!
;
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