0

this is my code, iv seen the other possibilities of getting this error and corrected them but i still get it.

bool move(int tile) {

int a = board[d][d];
 for(int i =0; i<d;i++)
{
    for( int j=0;j<d;j++)
    {
      if((board[i][j] == tile) && ( a == board[i+1][j] || board[i-1][j] || board[i][j+1] || board[i][j-1]))    
      {
        return true;
      }
      else
        {
        return false;
        }

    }
}

}

bool won(void) {

 for(int i =0; i<d;i++)
{
    for( int j=0;j<d-1;j++)
    {
        if((board[i][j+1] > board[i][j]) && (i == d-1 && j == d-2))
        {
          return true;
        }
       else
        {
          return false;
        } 
    }
}

}

this is the error i get.

clang -ggdb3 -O0 -std=c11 -Wall -Werror -o fifteen fifteen.c -lcs50 -lm fifteen.c:225:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ fifteen.c:249:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ 2 errors generated. make: *** [fifteen] Error 1

0

I'm new to CS but this would be my suggestions.

1) bool always requires return false/true right before the very end }. By moving return false to the very end of each code (before the last } ) would fix your errors.

2) However, I see some problem with your code. Namely, for example, i-1, what would happen when i=0, at that time, your board will be board[-1][j]. The program will not show any error but indeed will try to look for this value outside of your board. This will have whatever value occupying the memory at that time. So, you should at condition so that the program does not search outside of your box. This apply to j as well and also consider i+1 or j+1 < d as well!

3) I don't think you have swap function in your move() yet. You need to (1) check if the top, bottom, left or right of tile is blank (your code does not have this part yet) and (2) swap the tile and the blank space (your code does not have this part either)

4) Your 'int a = board[d][d];` will return the wrong value. Recall that the index start at 0, so the dimension is d , is your last tile board[d][d]? (hint: your first tile is board[0][0])

Good luck!

| improve this answer | |

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