0

look at my code in the pastebin link i don't understand the errors that are coming: http://pastebin.com/tuE5s3Em the error on compilation was:

~/workspace/pset3/fifteen $ make fifteen
clang -ggdb3 -O0 -std=c11 -Wall -Werror -o fifteen fifteen.c -lcs50 -lm
fifteen.c:283:1: error: control may reach end of non-void function [-Werror,-Wreturn-type]
}
^
1 error generated.
make: *** [fifteen] Error 1
1
0

The error says that the function could reach it's end without returning a value as is expected from its declaration.

The code that triggers the error is this:

if(flag==0)
return true;
if(flag==1)
return false;

because all the the return statements in the function are inside conditions that could possibly not evaluate to true.

One way to solve this is:

bool won(void)
{
    //Some code...

    if (flag == 0)
    {
        return true;
    }

    return false;

that way one of the return statements will surely execute.

Other way to solve it is declaring flag as bool, and returning it:

bool won(void)
{
   bool flag = false;

   //...some code...

           if(board[i][j]==a[i][j])
           {
               flag=true;
           }
           else if(board[i][j]!=a[i][j])
           {
               flag=false;
           }

   //...some code...

   return flag;
}

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