Your function was missing a final return option.
If c is truly the final option, then change it to this:
public int mid(int a, int b, int c)
{
if ((a != b) && (a != c))
{
return a;
}
else if ((b != a) && (b != c))
{
return b;
}
return c;
}
thines01
Postaholic
2,425 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
The corrected function will return a or b or c.
The compiler complains because you made it look as if there was to be another option by enclosing the last option in an else statement.
Keep in mind, once the chosen option is reached, the function exits.
There is no danger in leaving the last return unwrapped -- in fact, it's essential.
If there are NO OTHER OPTIONS past a or b, then the final outcome MUST be c, right?
thines01
Postaholic
2,425 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
...Please understand that wrapping the return c in an "else" with no options is the SAME THING. It's just syntax. If you understand that, your coding projects will look more professional as they will contain less artificial syntax.
thines01
Postaholic
2,425 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402