0

Please go easy on me :( I feel like I'm over-complicating things.

bool move(int tile)
{
    // TODO
    int h;
    int k;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < d; j++)
        {
            if (board[i][j] == tile)
            {
                h = i;
                k = j;
            }
        }
    }

    int a = 0;
    int b = 0;
    if (moving(h, k, a, b))
    {
        int temp = board[h][k];
        board[h][k] = board[a][b];
        board[a][b] = temp;
    }
    else
    {
        return false;
    }
}


bool moving(int h, int k, int a, int b)
{
    //check up down left right
    if (board[h + 1][k] == 0)
    {
        a = h + 1;
        b = k;
        return true;
    }
    if (board[h - 1][k] == 0)
    {
        a = h - 1;
        b = k;
        return true;
    }
    if (board[h][k + 1] == 0)
    {
        a = h;
        b = k + 1;
        return true;
    }
    if (board[h][k - 1] == 0)
    {
        a = h;
        b = k - 1;
        return true;
    }
    else
    {
        return false;
    }
}

control may reach end of non-void function

It says right there that it'll return true or false in that if else statement but it thinks it's going to run forever.

Please send help. Thank you.

2
  • Where does it say return true; in the move function (which is a non-void function) ? – DinoCoderSaurus Feb 23 '17 at 13:51
  • Oh my go- thank you! This is me whos still trying to grasp making my own functions. Didnt realize return true was meant for my bool only. – Fixided Feb 23 '17 at 14:58

You must log in to answer this question.

Browse other questions tagged .