Results 1 to 2 of 2
Thread: Getting aggrivated!?!
- 04-04-2011, 07:40 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
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?
- 04-04-2011, 08:19 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
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)


LinkBack URL
About LinkBacks

Bookmarks