[Solved] If-else choosing random option rather than basing choice off of randomly generated number


I got the suspicion that your problem is that you declared the method as “static” (and most likely the variables “temp” and “price” as well), while trying to use it as an instance method.

Either make the method non static, or change it so that you have to pass “temp” and return the value directly instead of saving it in a static variable first.

public static double GetPrice (double temp)
{
    if (temp >= 0 && temp < 50)
    {
        return 0.50;
    } else if (temp >= 50 && temp <= 60) {
        return 0.55;
    }
}

solved If-else choosing random option rather than basing choice off of randomly generated number