void init(void)
// define a counter and populate the array
int c = 1;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
// fill the tiles in descending order
board[i][j] = d * d - c;
c++;
}
}
//make the last tile blank
board[d-1][d-1] = 0;
// if there are an odd number of tiles, switch 1 and 2
if ((d * d)%2 == 0)
{
board[d-1][d-2] = 2;
board[d-1][d-3] = 1;
}
void draw(void)
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{if (board[i][j] == 0)
// print the blank tile
printf(" _");
else
// the tiles in descending order
printf("%2d", board[i][j]);
}
printf("\n");
}
Ignore the brackets part if considering that a mistake. I did it here on purpose so as to upload the code properly. And the errors I get are as follows:
:) fifteen.c exists
:) fifteen.c compiles
:( init initializes 3x3 board correctly
\ expected file to be of length 18, not 26
:( init initializes 4x4 board correctly
\ expected file to be of length 38, not 48
Output in log.txt
{{15,14,13,12},{11,10,9,8},{7,6,5,4},{3,1,2,0}}
board
declared? And what is the exact error message you get?if(d*d)%2 == 0)