Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Angry Getting aggrivated!?!

    Here is a section of my code:

    public double getAverage(int sid)
    {
    double avg;

    if (sid == id1)
    {
    avg = (double) (test11 + test12) / 2;
    System.out.println(name1 + " has a " + avg + " average.");
    }
    else if (sid == id2)
    {
    avg = (double) (test21 + test22) / 2;
    System.out.println(name2 + " has a " + avg + " average.");
    }
    else if (sid == id3)
    {
    avg = (double) (test31 + test32) / 2; // add the right code
    System.out.println(name3 + " has a " + avg + " average.");
    }
    else
    System.out.println("error...");
    }//missing return statement error

    I am recieving the missing return statement error on that last line...not sure why... Any suggestions?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    That error is pretty descriptive - if you define a method to have a return value you must return a value. The method above defines a double return value, and the content of the method does not return anything - either change the method declaration to void or return a value. (For future reference, please post your questions in the appropriate forum category)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •