C Programming Question The output of my code is the left image. How do I make my othello board look like the right picture I provided? Could you correrct my code please. void initializeBoard(char board[ROW][COL]) { int i, j; for (i = 0; i < ROW; i++) { for (j = 0; i < COL; i++) { if ((i == 3 && j == 3) || (i == 4 && j == 4)) board[i][j] = 'O'; else if ((i == 4 && j == 3) || (i == 3 && j == 4)) board[i][j] = 'X'; else board[i][j] = SPACE; } } } // function displayBoard void displayBoard(char board[ROW][COL]) { int i, j; printf("|-----------------------------------------------------|\n"); printf("| | A | B | C | D | E | F | G | H |\n"); printf("|-----------------------------------------------------|\n"); for (i = 0; i < ROW; i++) { printf("| %d |", i + 1); for (j = 0; j < COL; j++) { printf(" %c |", board[i][j]); } printf("\n|-----------------------------------------------------|\n"); } printf("\n"); }
C Programming Question
The output of my code is the left image.
How do I make my othello board look like the right picture I provided? Could you correrct my code please.
void initializeBoard(char board[ROW][COL])
{
int i, j;
for (i = 0; i < ROW; i++)
{
for (j = 0; i < COL; i++)
{
if ((i == 3 && j == 3) || (i == 4 && j == 4))
board[i][j] = 'O';
else if ((i == 4 && j == 3) || (i == 3 && j == 4))
board[i][j] = 'X';
else
board[i][j] = SPACE;
}
}
}
// function displayBoard
void displayBoard(char board[ROW][COL])
{
int i, j;
printf("|-----------------------------------------------------|\n");
printf("| | A | B | C | D | E | F | G | H |\n");
printf("|-----------------------------------------------------|\n");
for (i = 0; i < ROW; i++)
{
printf("| %d |", i + 1);
for (j = 0; j < COL; j++)
{
printf(" %c |", board[i][j]);
}
printf("\n|-----------------------------------------------------|\n");
}
printf("\n");
}
Please refer below for your reference:
Language used is C:
I have added comments at required position:
void initializeBoard(char board[ROW][COL])
{
int i, j;
for (i = 0; i < ROW; i++)
{
for (j = 0; i < COL; i++)
{// Here the position should be 4*4 and 5*5
if ((i == 4&& j == 4) || (i == 5&& j == 5))
board[i][j] = 'O';
//Here it should be 4*5 and 5*4
else if ((i == 4 && j == 5) || (i == 5 && j == 4))
board[i][j] = 'X';
else
board[i][j] = SPACE;
}
}
}
Step by step
Solved in 2 steps