Question: THIS IS FOR C PROGRAMMING: I am working on the folliwng program that plays the game of battleship. I have been able to create the

THIS IS FOR C PROGRAMMING: I am working on the folliwng program that plays the game of battleship. I have been able to create the playerBoard and computerBoard to place my ships, and now need to create the salvos Board for both Player A and Player B.

How do I go about doing that?

I have included the code I have now and what I am trying to do. Thank you so much.

This is what I'm trying to do:

THIS IS FOR C PROGRAMMING: I am working on the folliwng program

This is my Code:

#include

#include

void initializeBoard(int **playerBoard, int **compBoard)

{

const int rows = 10,

cols = 10;

for (int i = 0; i

{

playerBoard[i] = (int *)malloc(sizeof(int)*cols);

compBoard[i] = (int *)malloc(sizeof(int)*cols);

for (int j = 0; j

{

playerBoard[i][j] = '-';

compBoard[i][j] = '-';

}

}

}

void printBoard()

{

const int rows = 10,

cols = 10;

int **playerBoard = (int **)malloc(sizeof(int *)*rows);

int **compBoard = (int **)malloc(sizeof(int *)*rows);

initializeBoard(playerBoard, compBoard);

{

printf("SHIPS ");

printf(" | ");

for (char c = 'A'; c

{

printf("%c ", c);

printf("| ");

}

printf(" ");

for (int i = 0; i

{

printf("%2d ", i + 1);

printf("|");

for (int j = 0; j

{

printf(" %c ", playerBoard[i][j]);

if (i == 10)

puts(""); //only triggers if i=10, 10x10grid

printf("|");

}

printf(" ");

}

}

puts(" ");

printf(" | ");

for (char c = 'A'; c

{

printf("%c ", c);

printf("| ");

}

printf(" ");

for (int i = 0; i

{

printf("%2d ", i + 1);

printf("|");

for (int j = 0; j

{

printf(" %c ", compBoard[i][j]) + "|";

if (i == 10)

puts("");

printf("|");

}

printf(" ");

}

}

//Each Player's game board should be initialized

/o ships have been placed on either board

int main(void)

{

printBoard();

return 0;

}

SHIPS: SALVOS: SHIPS A|BICIDIEIFIGIHIIJ IAIBICIDIEIFIGIHIIJ IAIBICIDIEIFIGIHIIJ

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!