This site requires JavaScript, please enable it in your browser!
Greenfoot back
Bassusour
Bassusour wrote ...

2016/3/18

return error

Bassusour Bassusour

2016/3/18

#
It gives me the error "missing return statement", even though I got both return types.
public boolean spørgsmåltegn()
    {
           if ( canSee(Risk.class) )
           {
               eat(Risk.class);
               Greenfoot.playSound("slurp.wav");
               if (Greenfoot.getRandomNumber(100)<50)
               {
               fd_spist = fd_spist + 2;
               return false;
           } 
           else
           {
              fd_spist = fd_spist - 1;
              return true;
           } 
         }
    }
Super_Hippo Super_Hippo

2016/3/18

#
Look, the 'else' refer to the second 'if'... As you intended the code, you might want the 'else' to execute if the condition in line 3 isn't passed. In this case, you need to use another '}' after line 10 and remove line 16.
You need to login to post a reply.