The game compiles and runs, passing all the other tests in check50 when entered manually, but on the step for testing init, check50 fails.

Here's the check50 output: https://sandbox.cs50.net/checks/309ade0761e44143bd6786aae3be531b

I have no idea what the error means. Could it be a problem in the math library? This is the code for init:

void init(void)
    int maxvalue = d*d-1;
    for(int i = 0; i < d - 1; i++) {
       for(int j = 0; j < d; j++){
            board[i][j] = maxvalue;
    for(int i = 0; i < d-1; i++) {
        board[d-1][i] = bottomrow;
    if(d % 2 == 0){
        board[d-1][d-2] = 2;
        board[d-1][d-3] = 1;
  • what is bottomrow and where is it initialized? I'm also curious why you felt it was necessary to initialize the last row with a separate loop. – Cliff B Jul 24 '16 at 20:40
  • it seems that your intention is to initialize the last element separately but you're not doing it correctly – MARS Jul 24 '16 at 22:48
  • @Cliff B bottomrow equals d-1 and is initialized the line above the second for loop. I must have accidentally deleted that line. The last row is separate because I originally had a blank space instead of a zero and got lazy when I changed it to match the check50 specifications. The code does compile and run, so I don't think the problem is with an uninitialized variable. – RyanM Jul 25 '16 at 1:06
  • 4
    Possible duplicate of Pset3 fifteen.c works fine but fails cs50 check? – DinoCoderSaurus May 7 '17 at 19:03

The init() function posted, along with the missing declaration for bottomrow, works fine when plugged into my code. Either the problem lies elsewhere, there was a transcription error posting the code, or a different version of the code is being used to make the executable, or there's another issue somewhere. ;-)

While the initialization of the last line is working correctly, it isn't efficient. You've already done all the needed work in the first loop. If you let i run to i

Have you changed something somewhere that you shouldn't have?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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