Question: This is for c programming: I am working on a battleship project. and have the following program working but I cannot figure out how to

This is for c programming: I am working on a battleship project. and have the following program working but I cannot figure out how to fix my columns: Please take a look at it and help. Thank you so much.

OUTPUT:

This is for c programming: I am working on a battleship project.

MY CODE:

include #include

void startBoard(int board[][10]) { int line, column; for(line=0 ; line

void showBoard(int board[][10]) {

int line, column;

printf("\t1 \t2 \t3 \t4 \t10"); printf(" ");

for(line=0 ; line

} printf(" "); }

}

void startShips(int ships[][2]){ srand(time(NULL)); int ship, last;

for(ship=0 ; ship

//let's check if this shot was not tried //if it was, just get out of the 'do while' loop when draws a pair that was not tried for(last=0 ; last

} }

void giveShot(int shot[2]) {

printf("Line: "); scanf("%d",&shot[0]); shot[0]--;

printf("Column: "); scanf("%d",&shot[1]); shot[1]--;

}

int hitship(int shot[2], int ships[][2]) { int ship;

for(ship=0 ; ship

void tip(int shot[2], int ships[][2], int attempt) { int line=0, column=0, row;

//count how many ships there is line/column for(row=0 ; row

printf(" Stats: %d: line %d -> %d ships column %d -> %d ships ",attempt,shot[0]+1,line,shot[1]+1,column); }

void changeBoard(int shot[2], int ships[][2], int board[][10]){ if(hitship(shot,ships)) board[shot[0]][shot[1]]=1; else board[shot[0]][shot[1]]=0; }

int main() { int board[10][10]; int ships[5][2]; int shot[2]; int attempts=0, hits=0;

startBoard(board); startShips(ships);

printf(" ");

do{ showBoard(board); giveShot(shot); attempts++;

if(hitship(shot,ships)){ tip(shot,ships,attempts); hits++; } else tip(shot,ships,attempts);

changeBoard(shot,ships,board);

}while(hits!=5);

printf(" Finished game. You hit the three ships in %d attempts", attempts); showBoard(board); }

4 2 0 1~2~3~4~5~6~7~8~9~-~L

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!