Array Problem

I am having to make a matching game for a program. I am almost finished but running into a problem. I don't know how to make the 2nd array take an integer along with the '*' when 2 cards have been successfully matched.

Also, how could I have it show the 2 cards that were turned over without saving them to that value?

A few lines of code are still in there just from me testing making sure things are working properly.
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
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

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

void checkCards(int myArray[][col], char cardBoard[][col], int x1, int x2, int y1, int y2);
void showArray (int array [][col]);
void shuffleCards (int myArray [][col]);
void displayBoard(int myArray[][4], char cardBoard[][4]);
void initializeBoard(char cardBoard[][col], int myArray[][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} };
char cardBoard[row][col];
int x1, x2, y1, y2 = 0;

	shuffleCards(myArray);
	initializeBoard(cardBoard, myArray);
	showArray(myArray);

	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;
		}
	
	//if ((x1 == x2) && (y1 == y2))
	//	cout << "derP";
	//else
	
	checkCards (myArray, cardBoard, x1, x2, y1, y2);	
	
	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], char cardBoard[][col]) {
	 
//	 int x = 0;
//	 int y = 0;
	 
	 cout << "    1 2 3 4 \n";
	 cout << "   =========\n";
	 
	 for(int x=0;x < 4; x++)
	 {
		cout << x+1 << " | ";
		for(int y=0;y < 4; y++)
		{
		   cout << cardBoard [x][y] << " ";
		}
		cout << "|\n";		
	 }
	 cout << "   =========\n";
}

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

void initializeBoard(char cardBoard[][col], int myArray[][col]) {
	 
	 int x = 0;
	 int y = 0;
	 
	 cout << "    1 2 3 4 \n";
	 cout << "   =========\n";
	 
	 for(x=0;x < row ; x++)
	 {
		cout << x+1 << " | ";
		for(y=0;y < 4; y++)
		{
		   cardBoard [x][y] = '*';
		   cout << cardBoard [x][y] << " ";
		}
		cout << "|\n";		
	 }
	 cout << "   =========\n";
}
//------------------------------------------------------------------------------------------------
void checkCards(int myArray[][col], char 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);
	 }
}
Topic archived. No new replies allowed.