CODE
#include<iostream>
#include<cstdlib>
using namespace std;
/*function prototypes*/
void init_board(int layout[4][4]);
void get_input(int& v1,int& v2);
void rand_seed();
int rand_input(int a,int B);
void swap(int& num1,int& num2);
bool check(int cord[4][4]);
/*THE MAIN FUNCTION*/
int main()
{
int m1,m2;
int board[4][4];
int statusboard[4][4];
int i,j;
cout <<" The memory game"<<endl;
cout <<" "<<"1 2 3 4"<<endl;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
cout <<" "<<"*";
cout<<endl;
}
init_board(board);
init_board(statusboard);
get_input( m1,m2);
system("PAUSE");
return 0;
}
/*This is the function to get the users inputs*/
/*the row and the column*/
void get_input(int& v1,int& v2)
{
cout <<"Please enter the row" <<endl;
cin >>v1;
cout <<"Please enter the column" <<endl;
cin >>v2;
}
/**this is the function to display the layout*/
void init_board(int layout[4][4])
{
int j,i;
for ( i = 0; i < 4; i++)
{
for(j = 0; j < 4;j++)
layout[i][j] = 0;
}
}
/*THE FUNCTION THA UPDATES THE BOARD*/
bool check(int cord[8][8])
{
int i,j,g;
if(cord[i][j] == g)
cout <<cord[i][j] <<endl;
else
cout <<"*"<<endl;
}
/* FUNCTION FOR INITIALIZING THE SEED*/
void rand_seed()
{
int seed = static_cast<int>(time(0));
srand(seed);
}
/*FUNCTIOON FOR GENERATING A RANDOM NUMBER */
int rand_input(int a,int B)
{
return a + rand()%(b - a + 1);
}
/*the swap function*/
void swap(int& num1,int& num2)
{
int temp;
temp = num1;
num1 = num2;
num2 = temp;
}
/*the function to shuffle the cards*/
void shuffle(int row[8],int n)
{
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
row[i] = row[j]);
}
}
I was asked to write a program tha plays the memory game.I must be able to use 16 cards that are laid in a 4x4 square and labeled with pairs of numbers from 1-8.The program should allow the player to specify the cards that he or she would like to select through a coordinate system. I cannot get this program to shuffle the cards in the array by repeatedly selecting two cards at random and swapping them and a two dimentional array that indicates if a card is face up or face down.Here is an example of what the program should do :
1 2 3 4
---------
1|8 * * *
2|* * * *
3|* 8 * *
4|* * * *
All the cards are face down except for the pair 8,which has been located at coordinates(1,1) and(2,3).