So I was given this assignment and I have started on it, but I am having a hard time with the double loops.
•int main(void) This function definition is finished. Make no changes to it. It contains an implementation of the basic algorithm described in the software requirements.
•void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]) Set up a double for loop that will iterate through each row and column of the board in order to fill the squares. Be sure to use the MAX_ROWS and MAX_COLUMNS constants in your 'for loop' source code instead of the literal numbers given for the those constants in the skeleton file.
Inside the innermost 'for' loop, store a BOMB_DIGIT in a square when the following probability formula is true: (rand() % (MAX_ROWS - 3) == 0), otherwise, put an EMPTY_SQUARE_DIGIT in the square. Be sure to use the BOMB_DIGIT and EMPTY_SQUARE_DIGIT constants in your source code.
•void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]) Set up a double for loop that will iterate through each row and column of the board in order to print (in a width of 3) the contents of each square as shown in the example-program-output.txt file. Inside the inner for loop, use an if-else structure to do the following. If a square contains the BOMB_DIGIT, then print the BOMB_SYMBOL. If, instead, a square contains the EMPTY_SQUARE_DIGIT then, print the EMPTY_SQUARE_SYMBOL; otherwise, print the numeric value stored in the square.
•void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS]) This function works in conjunction with the incrementTheNeighborSquares function to put the mine number clues onto the board. To modularize the implementation, this function handles the part of finding each bomb on the board. The other function handles the part about correctly storing the number clues.
Set up a double for loop that will iterate through each row and column of the board. Do the following inside the inner for loop. If a square contains the BOMB_DIGIT then call the incrementTheNeighborSquares function and pass it the board, the current row value, and the current column value.
•void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn) The algorithm checks all of the neighbor (i.e., adjacent) squares surrounding a bomb square. If a neighbor square does not contain the BOMB_DIGIT, then the value in the square is incremented by one. A double for loop is used to iterate through the row and column location of each neighbor square surrounding the bomb square. Because C++ does no range checking when an array is indexed, the algorithm checks that, also.
This function definition is already finished. Make no changes to it.
// ############################################
// The function definition below is finished. Make no changes to it.
void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn)
{
for (int row = bombRow - 1; row <= bombRow + 1; row++)
{
if ( (row >= 0) && (row < MAX_ROWS) )
{
for (int column = bombColumn - 1; column <= bombColumn + 1; column++)
{
if ( (column >= 0) && (column < MAX_COLUMNS) && (board[row][column] != BOMB_DIGIT) )
board[row][column]++;
} // End for column
} // End if
} // End for row
} // incrementTheNeighborSquares