Class Program

Please help me with my program for class. We are making a minesweeper program and I am stumped. Please tell me what I am doing wrong. My code is as follows....

#include <iostream>
#include <iomanip>
#include <time.h>

using namespace std;

// Global Constants
const int MAX_ROWS = 10;
const int MAX_COLUMNS = 10;
const int EMPTY_SQUARE_DIGIT = 0;
const char EMPTY_SQUARE_SYMBOL = '_';
const int BOMB_DIGIT = -1;
const char BOMB_SYMBOL = '#';
int row;
int column;

// Function Prototypes
void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]);
void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS]);
void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS]);
void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int row, int column);


// ############################################
int main(void)
{
int gameBoard[MAX_ROWS][MAX_COLUMNS];

srand(time(NULL));

fillTheGameBoard(gameBoard);

insertTheMineClues(gameBoard);

displayTheGameBoard(gameBoard);

system("pause");

return 0;
} // End main


// ############################################
void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])
{
for (int row = 0; row < MAX_ROWS; row++)
{
for (int column = 0; column < MAX_COLUMNS; column++)
{
if ((rand() % (MAX_ROWS - 3) == 0))
cout << BOMB_DIGIT;
else
cout << EMPTY_SQUARE_DIGIT;}
}
} // End fillTheGameBoard


// ############################################
void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])
{
for (int row =0; row < MAX_ROWS; row++)
{
for (int column =0; column < MAX_COLUMNS; column++)
{
if (board[row][column] == BOMB_DIGIT)
cout << BOMB_SYMBOL;
else if (board[row][column] == EMPTY_SQUARE_DIGIT)
cout << EMPTY_SQUARE_SYMBOL;
else
cout << row;
}
}
} // End displayTheGameBoard


// ############################################
void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS])
{
for (int row = 0; row < MAX_ROWS; row++)
{
for (int column = 0; column < MAX_COLUMNS; column++)
{
if (board[row][column] == BOMB_DIGIT)
incrementTheNeighborSquares(board[row][column])
}
}


} // End insertTheMineClues


// ############################################
// 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
Oh sorry. It is telling me in the function int main and the function void fillTheGameBoard [Error] 'srand' was not declared in this scope. I don't understand how I am supposed to declare srand. It is also giving me [Error] invalid conversion from 'int' to 'int (*)[10]' [-fpermissive] and [Error] too few arguments to function 'void incrementTheNeighborSquares(int (*)[10], int, int)' in the function void insertTheMineClues.
Yes, when I entered #include<cstdlib> it took care of the srand.
Ok I think I figured out the invalid conversion error and the too few arguments error. The only other error I have is for function void insertTheMineClues it says [Error] expected primary-expression before 'int'. I dont know what type of expression they are talking about.
closed account (48T7M4Gy)
Maybe this helps - I made the game array a char array instead of a int array. There were a couple of endl's missing too which make the original output a bit of a nightmare.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <iomanip>
#include <time.h>

using namespace std;

// Global Constants
const int MAX_ROWS = 10;
const int MAX_COLUMNS = 10;

const char EMPTY_SQUARE_SYMBOL = '.';
const char BOMB_SYMBOL = '#';

int row;
int column;

// Function Prototypes
void fillTheGameBoard(char board[MAX_ROWS][MAX_COLUMNS]);
void displayTheGameBoard(char board[MAX_ROWS][MAX_COLUMNS]);
void insertTheMineClues(char board[MAX_ROWS][MAX_COLUMNS]);
void incrementTheNeighborSquares(char board[MAX_ROWS][MAX_COLUMNS], int row, int column);

// ############################################
int main(void)
{
    char gameBoard[MAX_ROWS][MAX_COLUMNS];
    srand(time(NULL));
    fillTheGameBoard(gameBoard);
    insertTheMineClues(gameBoard);
    displayTheGameBoard(gameBoard);
    
    return 0;
} // End main


// ############################################
void fillTheGameBoard(char board[MAX_ROWS][MAX_COLUMNS])
{
    for (int row = 0; row < MAX_ROWS; row++)
    {
        for (int column = 0; column < MAX_COLUMNS; column++)
        {
            if ((rand() % (MAX_ROWS - 3) == 0))
                cout << BOMB_SYMBOL;
            else
                cout << EMPTY_SQUARE_SYMBOL;
        }
        cout << endl; // <--
    }
} // End fillTheGameBoard

// ############################################
void displayTheGameBoard(char board[MAX_ROWS][MAX_COLUMNS])
{
    for (int row =0; row < MAX_ROWS; row++)
    {
        for (int column =0; column < MAX_COLUMNS; column++)
        {
            if (board[row][column] == BOMB_SYMBOL)
                cout << BOMB_SYMBOL;
            else if (board[row][column] == EMPTY_SQUARE_SYMBOL)
                cout << EMPTY_SQUARE_SYMBOL;
            else
                cout << row;
        }
        cout << endl; // <-- ???
    }
} // End displayTheGameBoard

// ############################################
void insertTheMineClues(char board[MAX_ROWS][MAX_COLUMNS])
{
    for (int row = 0; row < MAX_ROWS; row++)
    {
        for (int column = 0; column < MAX_COLUMNS; column++)
        {
            if (board[row][column] == BOMB_SYMBOL)
                incrementTheNeighborSquares(board, row, column); // <-- ???
        }
    }
} // End insertTheMineClues

// ############################################
// The function definition below is finished. Make no changes to it.
void incrementTheNeighborSquares(char 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_SYMBOL) )
                    board[row][column]++;
            } // End for column
        } // End if
    } // End for row
} // incrementTheNeighborSquares 

..........
#.#..##...
....#.....
#.......##
.........#
..........
.....#....
#........#
..#.....##
..#.......
0000000000
1111111111
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9999999999
Program ended with exit code: 0
Last edited on
Topic archived. No new replies allowed.