I am working on a Battleship program for an assignment. I am having trouble trying to find a good way to place the ships. The idea I have been trying is filling a 10x10 array with zeros then replacing specific coordinates with c for carrier, d for destroyer, etc. But I haven't been too successful. If anyone has any ideas of how I can do this, or if you know a better way then any help or guidance will be appreciated.
Sorry This is the first time I have been anywhere online to help. And to answer the question. No I do not know how to do arrays that is part of the reason I asking for help. I have been reading through my textbook but I havent found anything similar and without a concrete understanding it has been hard to think beyond exactly what the book is saying. But this is the code I have so far just to create the stratagey board and the playing board and my attempt at placing the ships
//================================FillArray==========================================
void FillArray(int pboard[], int sboard[]);
{
//Statement
for(int y; y < col; y++);
{
printf("%d", y);//prints y axis boarder
for(int x=0; x < row; x++);
{
printf("%d", x);//prints x axis boarder
for(int y=0; y < col; y++);
pboard[row][col] = 0;
}//for
}//Fills array for play
for(int y; y < col; y++);
{
printf("%d", y);//prints y axis boarder
for(int x=0; x < row; x++)
{
printf("%d", x);//prints x axis boarder
for(int y=0; y < col; y++);
sboard[row][col] = 0;
}//for
}//Fills array for Ships
return;
}//FillArray
//================================PlaceShips==========================================
void PlaceShips(int air=5, int bat=4, int cru=3, int des=1, int sub=2);
{
char ship;
int x,y;
int k;
//Statement
printf("Enter first letter of ship name: ");
if(scanf("%c", ship) == a)
{ printf("You have 5 space, Please enter furthest left or futhest up coordinate: ");
scanf("%d%d", &x,&y);
while(x>10 && y > 10)
{
printf("Enter 1. to place ship vertically\nEnter 2. to place ship horizontally: ")
scanf("%d", &k)
for(k==1, y > 6, y++);
{ pboard[row][y-1] = a;
if(y<0 || y >9)
printf("error");
}
for(k==2, x > 6, x++);
{
pboard[x-1][col] = a;
if(x < 0 || x > 9)
printf("error");
}
}
}
}
Is this a good way to go about doing this, or are there more efficient ways. I tried structures similar to:
typedef struct
{
char id[5]={a,a,a,a,a}
char name[]=aircraft
int hits=5
} Aircraft Carrier
but i wasnt sure how they would help.