### 2-D Arrays Code Help

For the 2-array program I have to do the following:

Create an init_board function that initializes your ocean (board) to all ‘O’ characters (you will need to pass in a two dimensional array). You can assume the board will always be square and you should use a single global constant for the size.
Create a print_board function that prints your Battleship board
Generate two random numbers (one for the row of the ship and one for the column)
Set up game play (using function(s) where useful) as follows:
Each turn, the user enters a guess for row and column
If they hit the ship, they win, end the game (the winning guess counts as a turn)
If they guess a spot they already guessed, print a message (this counts as a turn)
If they guess outside the bounds of the array, print a message (this counts as a turn)
If they miss, mark the spot in the array as missed (this counts as a turn)
Repeat until the player guesses the correct location.
When the user wins, print the total number of turn

This is what I currently have for my 2-array code. I do not know where to go from here: I need to do my print function but I am having trouble writing it.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879`` `````` #include #include using namespace std; const int S=4;// can't change size once declared. Global any fucntion can use this v. void init_board(char nums [][S]); void print_board(); int main() { srand (time(NULL)); int indexrow = rand() % 10; int indexcolumn=rand() % 10; int row, column; char ocean[S] [S]; cout<< "Let's Play Battleship!!!"<< endl; init_board(ocean); print_board(); cout<<"Enter a guess for the boat row: "<> row; cout<<"Enter a guess for the boat column:" <> column; /* for(int row = 0; row <4; row++) { } for(int column = 0; column <4; column++) { }*/ return 0; } void init_board(char nums [][S])/// fucntion defen { for (int i=0; i<4; i++) { for(int j=0; j<4; j++) { nums[i] [j]='O'; cout<< nums[i][j]<< " "; } cout<< endl; } } void print_board() { } ``````
Interesting. You two must be in the same class.
See this thread I am helping the other guy on:
http://cplusplus.com/forum/general/98335/
Topic archived. No new replies allowed.