0

I'm not sure what to do exactly. I get some errors that say that displayBoard is declared as an integer yet, I have it declared as void. I'm not sure where these are coming from and they are impeding me from continuing with my work. I would appreciate any pointers as to what to do.
Thank you.

#include<fstream>
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
const int ROWS= 4;
const int COLS= 4;
 
void displayBoard (int [][COLS], int size, int [][COLS], int size2); //displays the current situation of the board
void shuffleBoard (int arry[][COLS], int arry[][COLS]); //shuffles the cards at the beginning of the game. 
int Random(); //generates a random number between 1 and 8
void swap(int& v1, int& v2); //swaps two values

int main ( )
{
    bool winner;
    int Board[ROWS][COLS] = {{ 1, 1, 2, 2}, //initializing the board
                      {3, 3, 4, 4},
                      {5, 5, 6, 6},
                      {7, 7, 8, 8}};
    int Reveal[ROWS][COLS] = {{ 0, 0, 0, 0}, //the board that determines whether or not card has been selected or revealed
                      {0, 0, 0, 0},
                      {0, 0, 0, 0},
                      {0, 0, 0, 0}};
    int coordinate1, coordinate2;
    cout << "This is a memory matching game" << endl;
    cout << "There are 16 cards and 8 pairs" << endl;
    cout << "Pick a coordinate to reveal the card and then another to try and match it" << endl;
    while (!winner)
    {
    displayBoard(Board, ROWS, Reveal, ROWS); //not done yet
    cin >> coordinate1 >> coordinate2;
    }
    if (winner)
       cout << "You finished the game";
    
    getchar();
    return 0;
}

void displayBoard (Board[][], ROWS, Reveal[][], ROWS) //this is where the problem lies
{
     const int SIZE = 16; //size of the board
     int x = 0, y = 0;
     for (int i = 0, i <= 16, i++)
     {
         if (Reveal[x][y] == 1)
         {
            cout << Board[x][y];
            x++;
            y++;
         }
         else 
         {
            cout << "*";
         }
     }
}





void shuffleBoard(Board[][4])
{
     int v1, v2, j1, j2;
     const int TIMES = 16; //times to shuffle
     for (int i = 0, i < TIMES, i++)
     {
         v1 = Random();
         v2 = Random();
         j1 = Random();
         j2 = Random();
         swap(Board[v1][j1], Board[v2][j2])
     }   
 }
 
int Random()
{
    int x;
    srand (time(NULL)); //gets a new seed based on the time
    int const M = 1, N = 8;
    x = (M+(rand()%(N-M+1)));
    return x;
}

void swap (int& v1, int& v2)
{
     int temp;
     temp = v1;
     v1 = v2;
     v2 = temp;
}
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by ArkM
0

Of course, you have a problem with incorrect function header. You must declare parameter list in the header:

void displayBoard (int board[][COLS], int rows, int reveal[][COLS], int whatelse)
...

Have you ever seen C++ syntax description? Don't mix function call expression with function header!..

Additionally you have erroneous prototype:

void shuffleBoard (int arry[][COLS], int arry[][COLS]);

The arry paremeter name declared twice. I think there is the same error source in that case; misunderstanding of one of the basic language concepts...

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.