I've been working on pset3 game of fifteen in cs50 and when working on the draw function, the first output is exactly how it should be. However, if I restart the game by entering zero, then compiling again with ./fifteen #, that's where things get weird. The correct output is there, but on top of that, there are the top one or two lines from the previous run of the game. For example,
./fifteen 5
24 23 22 21 20
19 18 17 16 15
14 13 12 11 10
9 8 7 6 5
4 3 2 1 __
Tile to move: 0
the zero ends the game.
Then, ./fifteen 3
24 23 22 21 20
19 18 17 16 15
24 23 22 21 20
19 18 17 16 15
8 7 6
5 4 3
1 2 __
this is the output. It seems pretty random to me and it's really confusing. It runs fine except for this extra output. Is this because I haven't finished the game yet, or because there's something wrong with my draw code? Here is my draw code:
void draw(void)
{
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] > 9)
{
printf("%d ", board[i][j]);
}
else if (board[i][j] > 0)
{
printf("%2d ", board[i][j]);
}
else
{
printf("__");
}
}
printf("\n");
}
}
Thanks!