The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

# Thread: Why won't the grid generate?

1. ## Why won't the grid generate?

Hello! Trying to figure out why my grid for my memory game won't generate, I have all the code ready and it compiles. Heres my code...

// ----------------------------------------------
// Program Name: Memory
// Program Number: 5
// Submitted by: Chris Duncan
//
//
// By submitting this program with my name, I affirm that the creation and
// modification of this program is primarily my own work.
// ----------------------------------------------

#include "stdio.h"
#include "stdlib.h"
#include "memory.h"
#include "time.h"

void Generate(int grid[5][6]);
void display(int grid [5][6],int matched [5][6]);
int main()
{
int grid[5][6];
int matched[5][6];

int i=0, j=0;
int r = r % 5;
int c = c % 6;

// Generate the matched grid
for (i=0; i<5; i++)
{
for (j=0; j<6; j++)
{
if (i==0 || j==0 || i==j)
{
matched[i][j] = 0;
} // end of if

else
{
matched[i][j] = 1;
} // end of else

} // end of for j

} // end of for i

// Display the grid
// Display(grid, matched);

system("pause");

} // end of main()

// Generate the grid
Generate(grid);
// Algorithm for Program 5
void Generate(int grid[5][6])
{
int row, column = 0;
int r = 0, i = 0, j = 0;
// Fill grid with value 0

// Loop through rows
for ( i = 0; i < 5; i++ )
{

// Loop through the columns
for ( j = 0; j < 6; j++ )
{

// Store the value 0 at the current position
grid[i][j] = 0;
}// end of loop

}// end of loop

srand(time (NULL));
// Loop 15 times
for (i=0; i<15; i++)
// Generate a random number 1 - 99
r = rand();
r = (r - 0) * (100 - 1) / (RAND_MAX - 0) + 1;

// Loop as long as position picked contains a value
do
{
// Pick a random row
row = rand() % 5;
// Pick a random column
column = rand() % 6;

} while (grid [row] [column] !=0);// end of loop

// Store the value at the chosen location
grid[row] [column] = r;

// Loop as long as position picked contains a value
do
{
// Pick a random row
row = rand() % 5;
// Pick a random column
column = rand() % 6;

} while (grid [row] [column] !=0);// end of loop
{
// Store the value at the chosen location
grid[row] [column] = r;

}// end of loop
}// end of function

void display(int grid [5][6],int matched [5][6])
{
int i=0, j=0;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 6; j++)
{
if (matched[i][j] == 0)
{
printf("%c", 177);
} // end of if
else
{
printf("%i", grid[i][j]);
} // end of else

} // end of loop

} // end of loop

} // end of function

now the "generate(grid);" is suppose to make my 5 by 6 grid appear, but when I compile its just a blank screen. So, how do I fix this?

2. 27
posts
Registered User
i see that the funciton is generating the grid correctly (at least form what i can see, although i wouldn't choose that way).

Anyway, you aren't calling display anywhere, You have one that is commented out. But you need to call display at sometime.

3. okay, i uncommented it, it still compiles but gives me "undefined reference to 'Display' "

4. 27
posts
Registered User
i took the time to look at some of the formating, first of all your "GenerateGrid" appears to not even be in any sort of code. It is outside main. Not sure what programming tool you are using, but make sure you tab things so that it is easy to read.

as far as the error you are currently experience is becuase your prototype at the top is display and the call is Display. You have a different case of d's. I would also suggest to take up this naming convention.