0

I have a problem with compiling a fifteen.c. I've made init and draw functions with good result, they compile and work as they should, but when I moved forward I have some kind of bug with move function.

bool move(int tile) { tile = board[i][j]; //assigns tile as board

if (0 == board[i+1][j]) //down
{
             board[i][j] = board[i][j] + board[i+1][j];
             board[i+1][j] = board[i][j] - board[i+1][j];
             board[i][j] = board[i][j] - board[i+1][j];
}
else if (0 == board[i-1][j]) //up
{
             board[i][j] = board[i][j] + board[i-1][j];
             board[i-1][j] = board[i][j] - board[i-1][j];
             board[i][j] = board[i][j] - board[i-1][j];
}
else if(0 == board[i][j+1]) //right
{
             board[i][j] = board[i][j] + board[i][j+1];
             board[i][j+1] = board[i][j] - board[i][j+1];
             board[i][j] = board[i][j] - board[i][j+1];
}
else if (0 == board[i][j-1]) //left
{
             board[i][j] = board[i][j] + board[i][j-1];
             board[i][j-1] = board[i][j] - board[i][j-1];
             board[i][j] = board[i][j] - board[i][j-1];
}
else
{
  return false;
}

}

And when I try to compile the file I have 1 error "fifteen.c:259:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] }"

I've also introduced int i and int j at the very beginning of the code in order to make computer remember those variables.

I would be really glad if anyone would be able to help me with this ^^

1

For your code to compile, move has to return a value in every case. Your code will currently only return something if the else statement executes. This is because the function is "non-void", or not void, or in other words, it will return something.

You must log in to answer this question.

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