So this is a matching game, flip over two cards, if they match they stay up if not they flip over again. I have the matching system and coordinate system working. My problem is that when i use my array of zeros to "hide" the numbers, all that is ever output is the zeros.

Any ideas on why this might be happening? also any ideas on using something other than the number 0 for my grid? like an *? i couldn't figure out how to get an array to take them.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    char comma;
	int row1, column1, row2, column2, cards[4][4], cards_unflipped[4][4] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} , counter(0);

    srand((unsigned)time(NULL));
    
	//fill board with pairs
	bool makeNext = false;
	bool nullexists = true;
	memset(cards, 0, sizeof(cards));
	srand(time(NULL));

		for( int i = 1; i < 9; i++ )
			{
				makeNext = false;
				while(!makeNext)
					{
						int x1, y1, x2, y2;
						x1 = rand()%4;
						y1 = rand()%4;
						x2 = rand()%4;
						y2 = rand()%4;
						if( (x1 != x2 || y1 != y2) && (cards[x1][y1] == 0 && cards[x2][y2] == 0) )
						{
							cards[x1][y1] = i;
							cards[x2][y2] = i;
							makeNext = true;;
						}
					}
			}
					for( int i = 0; i < 4; i++ )
					{
						for( int c = 0; c < 4; c++ )
						{
							cout << cards[i][c] << " ";
						}
						cout << endl;
			



					}
    //display board
   while (nullexists = true)

   {
	   //selection
    cout<<"Please select the first card row and column seperated by a comma.\n";
    cin>>row1>>comma>>column1;

    cout<<"Please select the second card row and column seperated by a comma.\n";
    cin>>row2>>comma>>column2;

	  
	 
	   if (cards[row1][column1]==cards[row2][column2])

	   {
		    cards_unflipped[row1][column1] = cards[row1][column1];
			cards_unflipped[row2][column2] = cards[row2][column2];


			counter = counter++;
				if (counter == 8)
				{
					bool nullexists = false;
				}

	   }

	   //reveal the flipped cards
    cout<<"    1 2 3 4\n";
    cout<<"  ";
    for (int i=0; i<=8; i++)
    {
        cout<<"-";
    }
    cout<<endl;
    for (int r=0; r<4; r++)
    {
        cout<<r+1<<" | ";
        for (int c=0; c<4; c++)
        {
           
                cout<<cards_unflipped[r][c]<<" ";
            }
		cout<<endl;
        }
        
    }

   cout << "You Won!" << endl;
  

    return 0;
}

so i think i figured out that its the check if the values are = is broken not sure why though

Figured it out.

so i think i figured out that its the check if the values are = is broken not sure why though

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.