I am a newbie and have been working on this project for several days. I have received help thus far from Dani and it's been fruitful.
The project entails a "memory matching" game with 16 cards, labeled 1-8 in pairs. The cards are "shuffled" and placed face down on a table--User inputs choices for 2 cards (based on x-y coordinates) and those 2 choices are "flipped" up. If they are a match, they stay up, if not, they must be "pushed" off the board with ****. Game continues until all cards are up. I am at the outputting asterisks stage, and don't quite know how to proceed. The project also formats the "table" with 1-4 and dashes "around" the x and y so that the player can "see" coordinates to choose from. I have most of my display doing that, except I can't seem to get the 1-4 to correspond appropriately on the x axis. If I could get the table formatted properly, and have my "cards" face down (****), then I could move on to my conditionals and random for "shuffling." Thank you for an help

#include <iostream>
using namespace std;

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

   int fill_values();
   int card_defacer();
   int show_grid();

   int main(){




   int fill_values() //Defining Function establishes 16 cards with paired numbers from 1-8

	 return 0;

  int card_defacer()
  for(int x = 0; x < 4; x++)
  for(int y = 0; y < 4; y++)

  return 0;

int show_grid()// Function that will show the "playing table" and output values of only "pairs" other values will be "*******"

// cout << "USER enter a coordinate choice for your card:  " << endl; //these are only ideas
// cin >> choice1;
// cout << User, enter your second choice:  " << endl;
// cin >> choice2;

		cout<<"    " << "1       2       3       4  " << endl; //this 1-4 works and lays over (y)
        cout <<"    " <<"-------------------------"<< endl; // 1-4  indicators separated from table
		cout << endl;
cout <<endl;
		cout <<"|1";// not placing the number in the right place - causes first horizontal of card_value to indent

	    for(int x = 0; x < 4; x++){
		for (int y = 0; y < 4; y++){

		cout <<"    "<< card_value[x][y]<<  "   ";

		cout << endl;
		cout << endl;

return 0;
9 Years
Discussion Span
Last Post by Duoas

Yes, your comment is absolutely right. Placing something at the beginning of the line will absolutely cause anything else on the line to be shifted rightward.

Since your lines have fixed spaces fore and aft of each card, why not add a couple of spaces to the "header" line that numbers the grid?

// Instead of:
cout<<"    " << "1       2       3       4  " << endl;
// Use:
cout<<"      " << "1       2       3       4  " << endl;

(Notice how I added two spaces to account for the "1|"?)

Hope this helps.


Yes, your comment is absolutely right. Placing something at the beginning of the line will....
Thank you, but nomatter how many spaces I include, the "|1" still "pushes" my display. I've tried "cout-ing" it everywhere, as well as adding and removing spaces from various parts of the display to no avail, I'm obviously missing something. The top lines up nicely, now I need to label 1-4 rows.....Also, need to "cover up my cards" with asterisks..............Thank you everybody,


Maybe this syntax will allow for nice looking columns.

char space = ' ';
char bar = '|';

//Header line:
cout << space << space << 1 << space << 2 << space << 3 << space << 4 << endl;

//line 2:
cout << 1 << bar << grid[0][0] << space << grid[0][1] << space << grid[0][2] << space << grid[0][2] << endl;

Should work if the width of each char being displayed is the same in the font being used to display the results. Not all fonts are that way though.

To cover up the cards with asterixes declare a two dimensional char array rather than a two dimensional int array and initialize it to all asterixes. Once a match occurs display the matched values instead of *s in the appropriate cell of the masked array by assigning the value of the match in the masked array in the corresponding cells where they are in the answer array before displaying the masked array again.


Read more carefully. Since the "1|" is going to push your display no matter what, just push the top line the same amount with a couple spaces.

Hope this helps.


Read more carefully. Since the "1|" is going to push your display no matter what, just push the top line the same amount with a couple spaces.
I DID try that, and for some reason, it doesn't work..


Alright. Try this:

int show_grid()
  cout << "    1  2  3  4\n"
       << "  +------------\n";
  for (int x = 0; x < 4; x++)
    cout << setw( 2 ) << y << "| ";
    for (int y = 0; y < 4; y++)
      cout << card_value[x][y] << "  ";
    cout << '\n';
  cout << endl;

You might want to add a little if statement in the center loop to check whether you are supposed to print the card value or a '*'.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.