0
include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

const int Rows = 5;
const int Cols = 5;
enum Minesweeper { Mine = '@', Blank = '*', Loss = 'X'};

void StudentInfo ( );
void Information (int mines);
void make_board (Minesweeper Board [][Cols], int Rows);
void place_mines (int& x, int& y, int mines, Minesweeper& Board [][Cols]); /* I pass the initialized Board array into another function that will place new characters in the array */

int main ( )
{
        int mines = 0;
        int x = 0;
        int y = 0;

        StudentInfo ( );

        Minesweeper Board [Rows][Cols];

        cout << "       Enter amount of mines (5 - 10): ";
        cin  >> mines;

        Information (mines);

        cout << "Preparing Board... \n";
        cout << endl;

        make_board (Board, Rows);

After this function has run Board [Rows][Cols] should be '*'

        place_mines (x, y, mines, Board);

This function is to replace some of the '*' with '@' in random locations within the array

        return 0;
}

I'm trying to pass that already initialized Board into another function by refernece so taht it will print out a new character.

 void place_mines (int& x, int& y, int mines, Minesweeper& Board [][Cols]) /* In this function is states that 'mines' and 'Board' are not  declared in the scope */

{

        srand (time (0));
        for (int k = 0; k < mines; k++)
        {
                int x = (rand ( ) % 5);
                int y = (rand ( ) % 5);

                Board [x][y] = Mine;
                cout << static_cast<char> (Board [x][y]);
        }

        return;
}

void make_board (Minesweeper Board [][Cols], int Rows)
{
        int i = 0;
        int j = 0;

        for (int i = 0; i < Rows; i++)
        {
                for (int j = 0; j < Cols; j++)
                {
                                Board [i][j] = Blank;
                                cout << static_cast<char> (Board [i][j]) << ' ';
                }
        cout << endl;
        }

        Board [Rows][Cols] = Board [i][j];

        return;
}

This is the error I keep getting from the compiler

Minesweeper.cpp:13:72: error: declaration of ‘Board’ as array of references
Minesweeper.cpp:66:72: error: declaration of ‘Board’ as array of references
Minesweeper.cpp: In function ‘void place_mines(...)’:
Minesweeper.cpp:70:29: error: ‘mines’ was not declared in this scope
Minesweeper.cpp:75:17: error: ‘Board’ was not declared in this scope

Any Help would be greatly appreciated!

  • `error: declaration of ‘Board’ as array of references` says it all. You weren't declaring `Board` as a reference argument, which would be `Board[][Cols]&`, you were declaring it as a 2-d array of references, which is an error. – user207421 Apr 17 '15 at 04:04

1 Answers1

0

Arrays are passed by reference (by default) so I think you will find the '&' in the function prototype before the array is unnecessary.

You may want to see this question: how do I pass a reference to a two dimensional array to a function

Community
  • 1
  • 1
Dweeberly
  • 4,668
  • 2
  • 22
  • 41