bool help

Had to write a program that plays a card game. I can't seem to get my logic to work for when it is the end of the game. Here is my code if someone can catch what I'm doing wrong.

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

const int row = 4;
const int col = 4;

void checkCards(int myArray[][col], bool cardBoard[][col], int x1, int x2, int y1, int y2);
void showArray (int array [][col]);
void shuffleCards (int myArray [][col]);
void displayBoard(int myArray[][col], char cardBoard[][col]);
void initializeBoard(bool cardBoard[][col], int myArray[][col]);
bool gameOver (bool cardBoard[][col]);

int main () {
		
srand (time(0));
int myArray [row][col] = { {1,1,2,2},{3,3,4,4},{5,5,6,6},{7,7,8,8} };
bool cardBoard[row][col];
int x1, x2, y1, y2 = 0;

	shuffleCards(myArray);
	initializeBoard(cardBoard, myArray);
	showArray(myArray);
	
	do {
	cout << "Please enter the x position followed by the y position of the card you would like to flip." << endl;
	cin >> x1 >> y1;
	cout << "Enter the x and y position of the second card." << endl;
	cin >> x2 >> y2;

    	while ((x1 == x2) && (y1 == y2)) {
    	cout << "Those coordinates were duplicates!" << endl;
		cout << "Please enter the x position followed by the y position of the card you would like to flip." << endl;
		cin >> x1 >> y1;
		cout << "Enter the x and y position of the second card." << endl;
		cin >> x2 >> y2;
		}
	checkCards (myArray, cardBoard, x1, x2, y1, y2);
}
	
	while ((gameOver(cardBoard)) != (false));
	
		
	
	return 0;
}

//------------------------------------------------------------------------------------------------
void showArray (int array [][col]) {
	
	for (int i = 0; i < col; i++) {
	for (int j = 0; j < row; j++) {
    cout << array[i][j];
    }
	cout << endl;
	}
} 
//------------------------------------------------------------------------------------------------
void shuffleCards(int myArray[][col]) {
						     
    for (int s=0; s <= 20; s++){
    	
		int x = rand() % 4;
	   	int y = rand() % 4;
	
    	for (int i=0; i<row; i++) {
    		int temp=myArray[i][i];   
			myArray[i][i]=myArray[x][y];
        	myArray[x][y]=temp;
    	}
	}
}
//------------------------------------------------------------------------------------------------
void displayBoard(int myArray[][col], bool cardBoard[][col]) {

	 cout << "    1 2 3 4 \n";
	 cout << "   =========\n";
	 
	 for(int x=0;x <row; x++)
	 {
		cout << x+1 << " | ";
		for(int y=0;y <col; y++)
		{
			if (cardBoard [x][y])
		   cout << myArray [x][y] << " ";
		   else
		   cout << "* ";
		}
		cout << "|\n";		
	 }
	 cout << "   =========\n";
}

//------------------------------------------------------------------------------------------------

void initializeBoard(bool cardBoard[][col], int myArray[][col]) {
	 
	 cout << "    1 2 3 4 \n";
	 cout << "   =========\n";
	 
	 for(int x=0;x < row ; x++)
	 {
		cout << x+1 << " | ";
		for(int y=0;y < col; y++)
		{
		   cardBoard [x][y] = false;
		   cout <<  "* ";
		}
		cout << "|\n";		
	 }
	 cout << "   =========\n";
}
//------------------------------------------------------------------------------------------------
void checkCards(int myArray[][col], bool cardBoard[][col], int x1, int x2, int y1, int y2){
	
	x1--;
	x2--;
	y1--;
	y2--;
	 
	 cout << myArray[x1][y1] << " " << myArray [x2][y2];
	 
	 if (myArray[x1][y1] == myArray[x2][y2])
	 {
		cardBoard[x1][y1] = myArray[x1][y1];
		cardBoard[x2][y2] = myArray[x2][y2];
		
		cout << "Congratulations, you found a match!";
		cout << endl;
			displayBoard(myArray, cardBoard);
	 }
	 else
	 {
		 cout << "No match found.";
		 cout << endl;
		 	displayBoard(myArray, cardBoard);
	 }
}

bool gameOver (bool cardBoard[][col]){
	
	bool gameFinish = false;
	
		for (int x=0; x < row; x++)
			for (int y=0; y < col; y++)
				if ((cardBoard[x][y]) == true){
					return gameFinish = true;
				}
				else{
					return gameFinish = false;
				}
}

There is a problem with your gameOver function. Take a look at this.

1
2
3
4
5
6
bool gameOver (bool cardBoard[][col]){
	
	for (int x=0; x < row; x++)
		for (int y=0; y < col; y++)
			if ((cardBoard[x][y]) == true)return true;
}


Also, drawing the board looks incorrect.
That seems to have worked. What looks incorrect? It displays correctly. Have you tried running it?
Yes, I have tried. I think the X, Y edges are flipped. The input might be 2, 3, but then the picture says it is 3, 2.
Suggestion: format your code so it's easier to read...
A lot of the style was skewed upon pasting it in so I apologize for that. Otherwise, I'm a fresh programmer so I feel like mine is decent compared to some of the code I have seen of others asking for help.
Granted, but:

line 33: indent the nested while loop, and any other nested loops

that's one example.

You are right though: it is better than most starting off. The most important thing, though, is to practice consistency above all else. Once you are consistent, then you will find the code is far easier to read.

Just a helpful tip. :) Keep at it.

***********************************************************************
Errors I have found in your code:

Line 18: use time(NULL) (time(0) will yeild the same seed every time)

I can't seem to find anything else (the formatting is throwing me waaay off), but if you ant to make it more efficient, and start some good practices (if it's allowed), you can look up passing by reference. Also, if it suits you, you can try to prototype (forward declarations without variable declarations): void check_cards(int*, bool*, int, int, int, int);. if you do that, though, look up constant correctness, and passing by reference. I assume the values are directly modified in that function (since you're returning void) so whatever that function modifies would have to be passed by non-constant reference (which doesn't create any new memory).

Anyway, just some tips.
Topic archived. No new replies allowed.