0

So in this program, the only output I am getting is _.

Help would be appreciated.

My init:

void init(void)
{
    // Initializing the game
    int square;
    square = (d*d) - 1;
    for (int i = 0 ; i < d; i++)
    {
        for (int j = 0 ; j<d ; j++)
        {
            board[d][d] = square;
            square--; //iterating and taking values
        }
        printf ("\n"); //new line after every iteration of a line
    }
    //if the board is even then the numbers are interchanged
    if (((d*d) - 1) % 2 != 0)
    {
        int temp = board[d-1][d-2];
        board[d-1][d-2] = board[d-1][d-3];
        board[d-1][d-3] = temp;
    }
    // for position of blank tile
    int blank; 
    blank = d-1;
}

My draw:

void draw(void)
{
    // starting a loop for printing
    for(int i = 0 ; i < d ; i++)
    {
        for(int j = 0 ; j < d ; j++)
        {
            // if the numbers are below 10
            if (board[i][j] < 10)
            {
                //special case of space
                if (board[i][j] == 0)
                {
                   printf("  _ ");            
                }
                else
                {
                    printf("  %i ", board[i][j]);
                }
            }
            else // if the size is more than 10
            {
                printf(" %i ", board[i][j]);
            }
        }
        printf("\n");//new line
    }
}

In debugger the code doesn't skip over the condition of 0.

0

Your init does this each time through the loops:

board[d][d] = square;

Shouldn't you be initializing each board value with board[i][j]?

Also, no need to print anything in the init function.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .