Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,113 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,753 people online right now. Registration is fast and FREE... Join Now!




Memory Game

 
Reply to this topicStart new topic

Memory Game, cannot get program to run properly

kgosi
11 May, 2007 - 12:45 AM
Post #1

New D.I.C Head
*

Joined: 4 May, 2007
Posts: 3


My Contributions
blink.gif
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).
User is offlineProfile CardPM
+Quote Post

rex-mundi
RE: Memory Game
11 May, 2007 - 01:02 AM
Post #2

New D.I.C Head
*

Joined: 13 Apr, 2007
Posts: 24


My Contributions
not being funny or anything but this would better be sorted in the c++ area as the lounge is for non programming problems
User is offlineProfile CardPM
+Quote Post

MarkoDaGeek
RE: Memory Game
11 May, 2007 - 04:06 AM
Post #3

Dirty Technophile
Group Icon

Joined: 13 Oct, 2001
Posts: 10,902



Thanked: 1 times
Dream Kudos: 970
Expert In: Computer Networking, Web Development, Blogging

My Contributions
allow me to move this to C++
User is offlineProfile CardPM
+Quote Post

Pontus
RE: Memory Game
16 May, 2007 - 12:30 PM
Post #4

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 529



Thanked: 2 times
Dream Kudos: 275
My Contributions
Something like another multi-demensional array but then with bools, so u can use this:
CODE
bool displayed[4][4];
int field[4][4];
for(int a = 0; a <4;a++){
       for(int b = 0; b <4;a++){
              if(displayed[a][b]==true)
                     cout<<field[a][b];
              else
                     cout<<"*"<<;
       }
}


This post has been edited by manhaeve5: 16 May, 2007 - 12:30 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:44PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month