2D array problem "Memeory Game"

Basically for the program it says to write a program that uses 16 cards that are laid out in a 4 x 4 square and are labeled with pairs of numbers from 1 to 8.Your program should let the user specify cards through a coordinate system.

Use a 2D array for the arrangement of cards and another 2D array that indicates whether a card is face up or face down.

I am unsure how to get the program to go back and forth between the 2 arrays. What I have so far is just the shuffle function and a test function I used to show my array.


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
 #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

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

void showArray (int array [][col]);
void shuffleCards (int array [][col]);

int main () {
	
srand (time(0));
int myArray [row][col];

	shuffleCards(myArray);
	showArray(myArray);

	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 cards[][col]) {
	
	int array [row][col] = { {1,1,2,2}, 
				             {3,3,4,4},
					         {5,5,6,6},
						     {7,7,8,8} };
						     
    for (int s=0; s <= 20; s++){
    	
		int x = rand() % 4;
	   	int y = rand() % 4;
	
    	for (int i=0; i<row; i++) {
    		int temp=array[i][i];   
			array[i][i]=array[x][y];
        	array[x][y]=temp;
    	}
	}
    showArray(array);
}
//------------------------------------------------------------------------------------------------

Last edited on
Anyone have any advice?
Topic archived. No new replies allowed.