Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is wrong with is code? int match = 1; // boolean (0/1) int col; for (col =

ID: 3677880 • Letter: W

Question

What is wrong with is code?

int match = 1; // boolean (0/1)
int col;

for (col = 0; col < BOARD_SIZE; col++) {
if (board[row][col] != mark) {
match = 0;
}
}

won = match;
}

return won;
}


//
// Determines if the 'mark' completely fills a column
// returns 1 if yes, 0 if no
//
int hasWonVertical(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
/* INSERT CODE HERE */
return 0; // Stub -- make this return the correct value
}


//
// Determines if the 'mark' completely fills a diagonal
// returns 1 if yes, 0 if no
//
int hasWonDiagonal(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
/* INSERT CODE HERE */
return 0; // Stub -- make this return the correct value
}


//
// Gets computer move by randomly picking an unoccupied cell
//
void getComputerMove(char board[BOARD_SIZE][BOARD_SIZE]) {
int row;
int col;

do {
row = rand() % BOARD_SIZE;
col = rand() % BOARD_SIZE;
} while (board[row][col] != BLANK_SYMBOL);

board[row][col] = COMP_SYMBOL;
}


//
// Gets human move by prompting user for row and column numbers
//
void getHumanMove(char board[BOARD_SIZE][BOARD_SIZE]) {
/* INSERT CODE HERE */
}


//
// Prints the board to the screen. Example:
//
// 0 1 2
// +---+---+---+
// 0 | X | | |
// +---+---+---+
// 1 | | O | O |
// +---+---+---+
// 2 | | | X |
// +---+---+---+
//
void printBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
/* INSERT CODE HERE */
}

//
// Clears the screen -- uses ANSI terminal control codes
//
void clearScreen(void) {
const char ESC = 27;

printf("%c[2J%c[H", ESC, ESC);

Our school only allows the GNU compiler fyi

This is the error I get ( i knoe line 15 is a careless error -i believe double check i think i just need a comma between the two.)

int match = 1; // boolean (0/1)
int col;

for (col = 0; col < BOARD_SIZE; col++) {
if (board[row][col] != mark) {
match = 0;
}
}

won = match;
}

return won;
}


//
// Determines if the 'mark' completely fills a column
// returns 1 if yes, 0 if no
//
int hasWonVertical(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
/* INSERT CODE HERE */
return 0; // Stub -- make this return the correct value
}


//
// Determines if the 'mark' completely fills a diagonal
// returns 1 if yes, 0 if no
//
int hasWonDiagonal(char board[BOARD_SIZE][BOARD_SIZE], char mark) {
/* INSERT CODE HERE */
return 0; // Stub -- make this return the correct value
}


//
// Gets computer move by randomly picking an unoccupied cell
//
void getComputerMove(char board[BOARD_SIZE][BOARD_SIZE]) {
int row;
int col;

do {
row = rand() % BOARD_SIZE;
col = rand() % BOARD_SIZE;
} while (board[row][col] != BLANK_SYMBOL);

board[row][col] = COMP_SYMBOL;
}


//
// Gets human move by prompting user for row and column numbers
//
void getHumanMove(char board[BOARD_SIZE][BOARD_SIZE]) {
/* INSERT CODE HERE */
}


//
// Prints the board to the screen. Example:
//
// 0 1 2
// +---+---+---+
// 0 | X | | |
// +---+---+---+
// 1 | | O | O |
// +---+---+---+
// 2 | | | X |
// +---+---+---+
//
void printBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
/* INSERT CODE HERE */
}

//
// Clears the screen -- uses ANSI terminal control codes
//
void clearScreen(void) {
const char ESC = 27;

printf("%c[2J%c[H", ESC, ESC);

Explanation / Answer

int main(void) { char board[BOARD_SIZE][BOARD_SIZE]; int humanWon = 0; // boolean (0/1) int computerWon = 0; // boolean (0/1) int move = 0; // Seed the random number generator srand(time(0)); initializeBoard(board); while ((move < (BOARD_SIZE * BOARD_SIZE)) && !humanWon && !computerWon) { clearScreen(); if ((move % 2) == COMPUTERS_TURN) { getComputerMove(board); } else { printBoard(board); getHumanMove(board); } computerWon = hasWon(board, COMP_SYMBOL); humanWon = hasWon(board, HUMAN_SYMBOL); move++; } clearScreen(); printBoard(board); if (humanWon) { printf(">>>> You won! "); } else if (computerWon) { printf("
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote