A common memory matching game played by young children is to start
with a deck of cards that contain identical pairs. For example, given six
cards in the deck, two might be labeled “1,” two might be labeled “2,”
and two might be labeled “3.” The cards are shuffled and placed face
down on the table. The player then selects two cards that are face down,
turns them face up, and if they match they are left face up. If the two cards
do not match, they are returned to their original position face down. The
game continues in this fashion until all cards are face up.
Write a program that plays the memory matching game. Use 16 cards that
are laid out in a 4x4 square and are labeled with pairs of numbers from 1
to 8. Your program should allow the player to specify the cards that she
would like to select through a coordinate system.

This is what the book shows for an expample
1 2 3 4
1 8 * * *
2 * * * *
3 * 8 * *
4 * * * *

For example, suppose the cards are in the following layout:^^
All of the cards are face down except for the pair 8, which has been
located at coordinates (1, 1) and (2, 3). To hide the cards that have been
temporarily placed face up, output a large number of newlines to force
the old board off the screen.

Hint: Use a two-dimensional array for the arrangement of cards and
another two-dimensional array that indicates if a card is face up or face
down. Write a function that “shuffles” the cards in the array by repeatedly
selecting two cards at random and swapping them. .

The professor says "You dont need to sue a random number generator to shuffle. You can just place the cards in a random order"

// Memory2.cpp 

#include <iostream>
using namespace std;

int card_face;
int card_value[4][4];
int card_value2;

//function declaration
int fill_values(card_value[4][4]);

 void fill_values(int card_values[4][4]);
int main(void)

		cout<< "Enter first coordinate."

int fill_values(int card_value[4][4]);
	  cout << fill_values << endl;
	  return 0;

 //cardface [i][j]=0
 //for(i=0; 1<4 ; i++)
 //for(j=0; j<4; j++

This is what ive got but keep getting errors and i don't know where to go with this...frankly i just dont think I'm ready to write a program like this, but my proffessor thinks so...hellpppp me asap pleeaasseee....

You need to pull out your textbook and look at some sample programs. Watch your syntax.

Whenever a professor says "hint" that's a good place to start. I see you have one 2D array for the card values. You still need a 2D array for whether or not the card is face up.

Here are some suggestions from me:
1. Your fill_values function is a good start, but needs help. The prototype should be: void fill_values( int &card_value[4][4] ) . Don't cout anything, and don't return anything.

2. Make a similar function that shuffles the cards like your professor hints: void shuffle_cards( int &card_value[4][4] ) . This function does something repeatedly (selects two cards at random and swaps their values). This suggests a loop. It doesn't matter how many times through the loop you go as long as it is sufficient to shuffle the cards. 100 to 200 times ought to do it. (Also, I don't understand the comment about the random number generator. If you want to do something randomly you must use a random number generator.) Since your cards are stored in a 4 x 4 matrix, you'll need four random numbers each time through the loop: two for each card to swap: a y in [0..3] and an x in [0..3].

3. Make a similar function that initializes all the cards displayed states: void fill_visible( bool &cards_visible[4][4] ) When the game starts they should all be invisible (or face-down).

4. Make a function that displays the cards. void show_cards( int &card_value[4][4], int &cards_visible[4][4] ) This does what it says: print 50 or so newlines and then display the cards as in the example.

Etc. As you keep the things you need to do as small, simple things, the program becomes much more manageable. Then all you need to do in main() is call the appropriate functions as needed.

Hope this helps get you started.

This article has been dead for over six months. Start a new discussion instead.