Greetings, its my first post here;
So i have done only programming in Python before and its my first time in C.
I am making a battleship game, in which the user is to input coordinates on a 10x10 board and, there are hidden boats in the board; the boats are randomized each time. Well the only problem is that i have the programming logic, but i dont know the syntax in C, everytime i try to run something i get like 100 errors..
I have made my board using a while loop;
This is what i have so far, a double array, and each x and y char '.' making the board..
My question is how would i add the random ships and the hits. I tried using printf to get coords and then scanf to get the numbers, but how do i like, put those numbers to match the array? I know i have to use if statements such as
if m n == 5, 5 .. see thats the thing i know what to do, i dont know how to write it out ? the syntax of C
Any help is appreciated.
So i have done only programming in Python before and its my first time in C.
I am making a battleship game, in which the user is to input coordinates on a 10x10 board and, there are hidden boats in the board; the boats are randomized each time. Well the only problem is that i have the programming logic, but i dont know the syntax in C, everytime i try to run something i get like 100 errors..
I have made my board using a while loop;
int main(void){
int sea[10][10];
int x;
int y=0;
int m=0;
int n=0;
while(y<10){
x =0;
while(x<10){
sea[x][y]=('.');
printf("%c",sea[x][y]);
x=(x+1);
}
printf("\n");
y=(y+1);
}
printf("\nPlease enter a coordinate to shoot at!\n");
scanf("%d%d",&m,&n);
}
This is what i have so far, a double array, and each x and y char '.' making the board..
My question is how would i add the random ships and the hits. I tried using printf to get coords and then scanf to get the numbers, but how do i like, put those numbers to match the array? I know i have to use if statements such as
if m n == 5, 5 .. see thats the thing i know what to do, i dont know how to write it out ? the syntax of C
Any help is appreciated.