0
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}}

8
  • Please provide us more of your code, where is board declared? And what is the exact error message you get?
    – Aizen
    Commented Aug 14, 2016 at 12:49
  • 1
    You are definitely missing a parenthesis here: if(d*d)%2 == 0)
    – ChrisG
    Commented Aug 14, 2016 at 15:11
  • I've uploaded the code. Please help. Its urgent. Commented Aug 14, 2016 at 19:20
  • Two questions: are you using the current year's pset3 package or an earlier year? Have you altered main() or any parts that weren't marked with //TODO? That error indicates an error in the size of the log file that's generated, not the output of draw.
    – Cliff B
    Commented Aug 15, 2016 at 2:25
  • I am using this year's pset3 package and I haven't altered with main function. Commented Aug 15, 2016 at 10:36

1 Answer 1

1

Your log should look like this when you first run the program:

15|14|13|12
11|10|9|8
7|6|5|4
3|1|2|0

Did you modify the code that writes to the log? Are you sure you are using the 2016 edX pset3 spec with the correct link to the source code? Here is fifteen.c. Be sure that's the version you are using. Based on what you say your log.txt shows, you are using the 2013 version of the distribution code.

You must log in to answer this question.

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