0

The compiler is showing "not all code paths return a value" for the CalculateCharges. Help!!

public decimal CalculateCharges()
        {
            decimal pay;
            decimal decHoursParked;
            decHoursParked = Math.Ceiling(_hoursParked);
            if (decHoursParked <= 3)
            {
                pay = 4;
            }
            else if (decHoursParked > 3)
            {
                pay = decHoursParked * 2 - 2;
            }
            if (decHoursParked >= 24)
            {
                pay = 12;
            }
}

Edited by mrjohnka: n/a

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Xcelled194
0

In line 1 you declare that you are going to return a decimal. Where is the return statement in your code?

0

Also, anywhere your function may exit, you need a return.

For example, consider:

bool GetError(bool error) {
if (error == true) {
    return true;
}
}

That snippet will throw the same error. What you need is

bool GetError(bool error) {
if (error == true) {
    return true;
}
return false;
}

Now in that example, it was pretty obvious. Just be careful if/when your methods start to get really intricate and convoluted.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.