Bool Functions???

I am attempting to write a program that will allow someone to play the matching game. The problem I have though is using a bool function. Somehow I am supposed to fill a a char 2d array with all stars and then as the player chooses cards to flip over and they match then they will stay. The char array is to be a 4x4 array filled with *'s and then when the correct pair of cards are chosen then that pair of numbers will continue to show.

How would i write a bool function to do this?

below is a code a friend helped me type but I'm not sure if it is right...



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const int SIZE = 4;


int main ()
{
	char answer;
	int X1, Y1, X2, Y2;
	int GameArray[SIZE][SIZE] = { { 1, 2, 3, 4},
								  { 5, 6, 7, 8},
								  { 1, 2, 3, 4},
								  { 5, 6, 7, 8} };

	
	bool isFaceUp[SIZE][SIZE];	// declaration for the number of rows and columns and the array size of 20 rows and 15 columns as a max
	
	for(int i = 0; i < SIZE; i++)			//set all values of isFaceUp to false so all cards are face down
	{
		for(int a = 0; a <SIZE; a++)
		{
			isFaceUp[i][a] = false;
		}
	}
closed account (D80DSL3A)
That looks good so far.
What do you want the 'bool function' to do?
Do you want it to return true if a match is made and false if not?
Assuming that you have gotten two row and column choices from the user then perhaps this will do:
1
2
3
4
5
// GameArray is passed to this function along with the users choices
bool isMatch( int GA[][SIZE], int row1, int col1, int row2, int col2 )
{
    return GA[row1][col1] == GA[row2][col2];
}

or do you need it to modify the (as yet non-existent) character array too?
Last edited on
Basically I was told by my professor that I need a bool function. Im told that I need one array for all of the numbers and then randomize those numbers in a 2D array. That array is a 4x4 that involeves the number 1-8. Then im told that i need another array 4x4 that is filled with stars (*) and will display the number if the player chooses correctly. The player will chose the coordinates when shown the table of all *'s and the number 1-4 across the top and the left side of the table.

I have another post on here that has the majority of my code which has not changed much. If you could look at that one too that would be very helpful.
Topic archived. No new replies allowed.