0

Im so close to finish fifteen. I have a mistake about syntax with the last } for my function Move() and Won(). Here the error message when I compile : fifteen.c:279:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ fifteen.c:300:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ 2 errors generated. make: *** [fifteen] Error 1. I red that it could be that it didn't see the end of the loop, because using else, I didn't listed all the possibilities ending. so as it proposed, i erase else, before false. But still the same error. Here are the code for my two function. Tks : `/** * If tile borders empty space, moves tile and returns true, else * returns false. */ bool move(int tile) //int tile is number choosen to move by the player { int i = 0; // row
int j = 0; // column int blank = 0; // blank's position

 // find the location of the number choosen by player 
for (i = 0; i < d; i++) 
{
    for (j = 0; j < d; j++)
    {
         //find blank's tile location 
        if (board[i][j] == 0)   
        {
            blank = board[i][j];
        }

        if (board[i][j] == tile)
        { 

             //check if tile's location is a legal move from the blank's tile
            if (i > 0)
            {
                if (board[i - 1][j] == blank) // if blank is above tile 
                {
                    board[i - 1][j] = tile;
                    board[i][j] = blank;
                    return true;
                }
            }

            if (i < d)
            {
                if (board[i + 1][j] == blank) // if blank is top tile 
                {
                    board[i + 1][j] = tile;
                    board[i][j] = blank;
                    return true;
                }
            }

            if (j > 0)
            {
                if (board[i][j - 1] == blank) // if blank is above left to
                {
                    board[i][j - 1] = tile;
                    board[i][j] = blank;
                    return true;
                }
            }

            if (j < d)
            {
                if (board[i - 1][j] == blank) // if blank is right to tile 
                {
                    board[i - 1][j] = tile;
                    board[i][j] = blank;
                    return true;
                }
            }
        return false;
        }
    }
}

}

/** * Returns true if game is won (i.e., board is in winning configuration), * else false.{ */ bool won(void) { for (int i = 0; i < d; i++) { for (int j = 0; j < d - 1; j++) { if (board[d - 1][d -1] == 0) { if (board[i][j + 1] < board[i][j]) return false; } return true; } } }`

2
  • put return false in the very end, just before last } – obesman Jul 8 '17 at 4:46
  • Thank you so much :) – Genevie Jul 10 '17 at 21:17

You must log in to answer this question.

Browse other questions tagged .