0

enter image description here

Everything is ok with the code, except of check50 which reports this one mistake, I assume problem is in my won function because everything else works. Can someone explain to me where mistake actually is? Thanks in advance

2

You return true too early. You only check whether all the tiles are in the correct order, but you don't check the position of the empty tile. A quick fix would be to replace

if (min == d*d)
{
    return true;
}
else
{
    return false;
}

with

return (min == d*d) && (board[d-1][d-1] == 0);

which additionally ensures that the last tile is the empty tile.

(I have some dislike for if (boolean expression) return true; else return false;, that's why I refactored that into a simple return statement, you could stay with that if, if you really want to, and just add the additional condition.)

| improve this answer | |
  • Yes, thanks man.. – faust91 Feb 7 '17 at 17:24
  • I assumed that if first d*d-1 elements are in right order, game is won.My logic failed me i guess.. Thanks anyway, you helped a lot. – faust91 Feb 7 '17 at 17:29
-2

Your code is exiting (return 0) instead of still taking in input, it is not solving the board using the file.

| improve this answer | |

You must log in to answer this question.

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