i made a multi dimensinoal aray for a battleship game, and the game is going to have a grid full of 0's, and if the user hits the ship, it turns the 0 to a 1. i have the code for the multidimensional array in a separate method.and when i call the moethod, i dont want to make a new grid, but delete the old one and make the new one when i change a value from 0 to 1 in the array then call the method
void print_num(){//function for refreshing grid
cout<<"12345678910"<<endl;
for (int j = 0; j <=9;j++){//column for loop
for (int i = 0; i<=9;i++){//row for loop
cout<<grid[i][j];
}
cout<<" "<<j + 1<<endl;//for formatting, makes grid correct
}
}
int main() {
for (int j = 0; j <=9;j++){//column for loop
for (int i = 0; i<=9;i++){//row for loop
grid[j][i] = 0;
}
}
print_num();
//guess from 1-
return 0;
}
how can i make print num delete the old grid completely and replace it?
if i change grid[5][4] to 1 (the "hit sign"), then use print_num, it makes a new grid and does not delete the old one.
Another problem: on the new grid that comes out one more then it should. for example grid [4][5] would mark 1 on the coordinated [5][6]. i know this has something to do with 0, but i cant quite find where i made the mistake