Question about boolean functions

So, our professor had asked us to make a program that displays a 5 X 5 board and randomly places bombs. I did that. Now, we are supposed to use that same program and add onto it. I know i am going to have many more problems, but I wan't to start with a simple problem that i just cant figure out.

My current code outputs a 5 X 5 board with the bomb visible and my professor has asked "Update the function to display the game board by adding another parameter
used to indicate whether or not to “reveal” the solution with all mines visible, or to
display the current, active board with mines hidden (showing the initial value ‘*’
instead). For squares containing a mine (i.e., ‘@’), if the boolean to reveal the
board is set to false, you are to display the ‘*’ character instead of ‘@’ so as
not to prematurely reveal the location of any of the mines.


I am having two main problems.

1) " adding another parameter
used to indicate whether or not to “reveal” the solution". what type of parameter do I add here? ? I know I am supposed to update the "display board" function,but I am not sure what to do here.

2) How do i display my board WITHOUT the bombs?

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Here is my code
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 #include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
//---------------------------Global Constants-----------------------------
const int ROWS = 5; // a constant of row 
const int COLS = 5; // a constant of column. I don't want the board to be more than 5 X 5

//enum to represent every possible value in the board.
enum Symbols {
	STAR = 42, AT = 64, X = 88, ZERO = 0, ONE = 1, TWO = 2, THREE = 3,
	FOUR = 4, FIVE = 5, SIX = 6, SEVEN = 7, EIGHT = 8, NINE = 9
};

typedef Symbols* SymbolsPtr;
//------------------
//--------------Structure-----------
struct coordinates
{
	int Rows[5]; //an integer member that holds the row position on the board
	int Cols[5]; //an integer member that holds the column position on the board
};
//-----------------------------------
//------------------------------------function-------------------------
void info();

void initPosition(Symbols symbolArr[ROWS][COLS]); 

bool checkMine(Symbols symbolArr[ROWS][COLS]);

void displayBoard(Symbols symbolArr[ROWS][COLS]);

//------------------------------------function-------------------------	
int main()
{
	srand(time(NULL));
	int mines;

	Symbols symbolArr[ROWS][COLS] = {STAR, AT, X, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
	
	do  //ask for number of mines between 5 and 10
	{
		cout << "Enter The Numbers of Mines Between 5 and 10: ";
		cin >> mines;
	}while(mines <= 4 || mines >=11);
	
	
		initPosition(symbolArr); //calling the function that initalizes the stars
		int count = 0; // counter set to 0
		do
		{
			if(checkMine(symbolArr) == true) //only if bool returns true, countinue
			{
					count++;
			}
			
		}while(count < mines); 		//loop the amount of time specifed by the user;
		
	displayBoard(symbolArr);	
		
	return 0;
}

void initPosition(Symbols symbolArr[ROWS][COLS]) //initalizes array so board starts with *
{
	for (int i = 0; i < ROWS; i++)
	{
		for (int j = 0; j < COLS; j++)
		{
			symbolArr[i][j] =  STAR;
		}
	}
	return;
}

bool checkMine(Symbols symbolArr[ROWS][COLS]) // function checks if at is in a array
{
		int randomRow = (rand() % ROWS); //randomize rows 
		int randomCol = (rand() % COLS); //randomize column
		
		if(symbolArr[randomRow][randomCol] != AT)   // if the function doesn't already contain a bomb, place and and return it
		{
			symbolArr[randomRow][randomCol] = AT;
			return true;
		}
		else  // else return false
		{
			return false;
		}
}

void displayBoard(Symbols symbolArr[ROWS][COLS]) // This function displays the board and the instructions is asking me to modify it. I am not sure how?
{
	{
		cout << "   0 1 2 3 4" << endl;
		cout << "+-------------+" << endl;

		for (int i = 0; i < ROWS; i++) //ROWS = 5
		{
			cout << i <<'|';
			for (int j = 0; j < COLS; j++) //COLS = 5
			{
					cout << " ";
					cout << static_cast<char>(symbolArr[i][j]) << "";
			}
			cout << " |"<<endl;
		}
		cout << "+-------------+" << endl;

	}
	return;
}
}



Thanks for any help

--
Last edited on
adding another parameter used to indicate whether or not to “reveal” the solution". what type of parameter do I add here

the answer might be hidden in your prof's notes:
if the boolean to reveal the
board is set to false


How do i display my board WITHOUT the bombs

have a default board with all *'s and print that when the bool reveal is set to false
Last edited on
so i am trying to do something that may or may not be possible. Currently, I am trying to pass a boolean function that can return true or false and then pass that on to another function.

My professor has said "adding another parameter used to indicate whether or not to “reveal” the solution with all mines visible, or to display the current, active board with mines hidden "

I have a void function that i have two pieces of code in. I am trying to seperate it so that if game playing equals true, then perform one piece of code. if game playing equals false, then perform another piece of code. I don't know how to do this though.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

void (array[rows][cols], //passing a parameter here)

  int main()
{
   bool game_playing = true;
    .....


    .....
   bool game_playing = false
}

void (array[rows][cols], //parameter here)
{
 if parameter = true
   {
       .......
   }
 else
    {
       ........
    }
}


How would I pass this parameter??
Topic archived. No new replies allowed.