Hi guys, here is my code.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void chooseNumber()
{
int gameRow, gameColumn;
cout << "Please enter two values, the row and column of the cell "
<< "you would like to pull from the gameboard." << endl;
cin >> gameRow;
cin >> gameColumn;
while( gameRow < 1 && gameRow > 9)
{
cout << "Please enter a number between 1 and 9 for the "
<< "row." <<endl;
cin >> gameRow;
}
while ( gameColumn < 1 && gameColumn > 9)
{
cout << "Please enter a number between 1 and 9 for the "
<< "column." << endl;
cin >> gameColumn;
}
cout << gameRow << gameColumn;
}
void displayBoard(int gameBoard[15][12])
{
cout << "Here is the board. \n" << endl;
for(int i= 0; i < 15; i++)
{
int column = 0;
for(int i= 0; i < 12; i++)
{
cout << gameBoard[i][column];
}
cout << endl;
column++;
}
}
int main()
{
int gameBoard[15][12];
srand ( time(NULL) );
cout << "Welcome to the Same Game. The rules are as follows: "
<< endl << "You will be given a 15x12 grid filled with "
<< "random integers spanning from 1 to 9. The object of "
<< "the game is to eliminate 'cells', or two or more "
<< "similar integers connected together vertically or "
<< " horizontally until the entire board is clear. If "
<< "you run out of moves, then it's game over. \n" << endl;
for(int i= 0; i < 15; i++)
{
int column = 0;
for(int i= 0; i < 12; i++)
{
gameBoard[i][column] = rand() % 9 + 1;
}
cout << endl;
column++;
}
displayBoard(gameBoard);
chooseNumber();
}
I am trying to pass 2D array gameBoard into the displayBoard function and display the board to the user. However, when I try to display my function, it only outputs the final row of my 2D array 12 times. Any help is appreciated!