Hi all i am working on a memory game and i am having problems inputing the data so it checks if a 3rd number is pulled up to ignore it
thanks in advance

int card[6][6],total=0,value,test; 
	srand((unsigned)time(NULL));//randomize timer

	for (int i=0;i<6;i++)
	{
		for (int j=0;j<6;j++)
		{
			value=rand()%18;//random
			test=0;
			card[i][j]=value;//sets the value
			for (int x=0;x<6;x++)
			{
				for (int y=0;y<6;y++)//starts the check for doubles
				{
					if(value==card[x][y])
					{
						test++;
						cout<<i<<endl;
					}
					if (test==3)
					{
						//need a code to stop for the 3rd one to be put in.
					}
				}
			}
		}
	}

It might help to describe how the game works and how your program logic accomplishes that. Saying that you need some code for the program to ignore a 3rd number that's pulled up means nothing to us.

well it is a memory game where you match 2 numbers
and i want random numbers between 0 and 17 on the board i need 2 of the same number on the board

So you want to populate the board with random numbers in the range of [0, 18) and disallow more than two of a kind? I'd say use a frequency table for the range since it's small, and repeat getting the random number until you find one that doesn't go beyond the limit:

#include <cstdlib>
#include <iomanip>
#include <iostream>

int main()
{
  using namespace std;

  int board[6][6];
  int freq[18] = {0};

  for ( int i = 0; i < 6; i++ ) {
    for ( int j = 0; j < 6; j++ ) {
      int r;

      do
        r = rand() % 18;
      while ( freq[r] >= 2 );

      ++freq[r];
      board[i][j] = r;
    }
  }

  for ( int i = 0; i < 6; i++ ) {
    for ( int j = 0; j < 6; j++ )
      cout<< left << setw ( 3 ) << board[i][j];
    cout<<'\n';
  }
}

The frequency table holds a count of all of the values in your range.

commented: Wow! O_O +5

oh wow that is a different way thinking about it. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.