Hello, I need some help with this code. First of all, the program just closes after I enter the rows. It's not supposed to do that. Then, the coordinates (cards) 1,1 and 2,3 need to face up when I start it. How do I do that? I hope someone can fix this for me. Thank you.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    char comma;
    int r1, c1, r2, c2, cards[4][4];
    srand((unsigned)time(NULL));
    //fill board
    for (int r=0; r<4; r++)
    {
        for (int c=0; c<4; c++)
        {
            cards[r][c]=rand()%8+1;
            cout<<cards[r][c];
        }
        cout<<endl;
    }
    //display board
    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<<"* ";
        }
        cout<<endl;
    }
    cout<<endl;
    //selection
    cout<<"Insert the first card row seperated by a comma.\n";
    cin>>r1>>comma>>c1;
    cout<<"Insert the second card row seperated by a comma..\n";
    cin>>r2>>comma>>c2;
    //fix
    r1--;
    c1--;
    r2--;
    c2--;
    //reveal
    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++)
        {
            if ((r==r1)&&(c==c1))
            {
                cout<<cards[r][c]<<" ";
            }
            else if((r==r2)&&(c==c2))
            {
                cout<<cards[r][c]<<" ";
            }
            else
            {
                cout<<"* ";
            }
        }
        cout<<endl;
    }
    //match?
    if (cards[r1][c1]==cards[r2][c2])
    {
    }
    else
    {
    }
    //this pushes the next board onto a blank screen
    for (int b=0; b<=20; b++)
        cout<<endl;
    //repeat
    return 0;
}

// Pause 

void pause(void)
  {
  cout << "\n\n";
  system("PAUSE");
  cout << "\n\n";
  return;
  }

Place lines 21 through 87 in a loop to allow for repetitive inputs.

Use cin to pause the program to await for further input or for viewing.

Is your board loaded correctly? Don't you need 8 unique pairs of numbers (1-8)? Your code just puts 16 numbers, each 1-8 in the board. There may be six 7s and zero 3s for example with your code.

Edited 7 Years Ago by Lerner: n/a

Place lines 21 through 87 in a loop to allow for repetitive inputs.

Use cin to pause the program to await for further input or for viewing.

Is your board loaded correctly? Don't you need 8 unique pairs of numbers (1-8)? Your code just puts 16 numbers, each 1-8 in the board. There may be six 7s and zero 3s for example with your code.

Hi

yeah, the board loads just fine. Just those 2 things aren't working yet. I'll try it.

This article has been dead for over six months. Start a new discussion instead.