This code simply doesn't seem to work. I can't seem to figure out why it isn't, but when I run it it seems to choose a random price from the options rather than go off what the temperature actually is. I'm also wondering if there would be a better way to implement what I'm trying to do rather than a huge if-else ladder. Thanks
public static double GetPrice ()
{
if (temp >= 0 && temp < 50)
{
price = 0.50;
}
else if (temp >= 50 && temp <= 60)
{
price = 0.55;
}
else if (temp >= 61 && temp <= 65)
{
price = 0.60;
}
else if (temp >= 66 && temp <= 70)
{
price = 0.65;
}
else if (temp >= 71 && temp <= 75)
{
price = 0.75;
}
else if (temp >= 76 && temp <= 80)
{
price = 0.80;
}
else if (temp >= 81 && temp <= 85)
{
price = 0.85;
}
else if (temp >= 86 && temp <= 90)
{
price = 0.90;
}
else if (temp > 90)
{
price = 1.00;
}
return price;
}
Aucun commentaire:
Enregistrer un commentaire