I cannot figure out why this code is not working. The output appears to be random. Any help is greatly appreciated. Thanks! My Init code:
void init(void)
{
int MAX = (d*d)-1;
int below = 0;
int board [d][d];
for (int i=0; i<d; i++)
{
for (int j=0; j<d; j++)
{
board[i][j] = MAX-below;
below++;
}
}
//if even switch 1 and 2
if (d/2 == 0)
{
int gridtwo;
gridtwo = board [d-(d-2)][d-(d-2)];
board [d-(d-2)][d-(d-2)] = board [d-(d-1)][d-(d-1)];
board [d-(d-1)][d-(d-1)] = gridtwo;
}
}
My draw code:
void draw(void)
{
int board [d][d];
for (int i = 0; i<d; i++)
{
for (int j = 0; j<d; j++)
{
if (board[i][j]==0)
printf("_ ");
else
{
printf("%d", board[i][j]);
printf(" ");
}
}
printf("\n");
}
Thanks again!
board[][]
variable again? I remember from this assignment, it is already declared as a global variable. you should not Change it. use that one.