lundi 17 août 2020

If, Else-If Logic Check

I have someone telling me that the logic in the if else-if below is not correct because I should have included an upper and lower limit in every else-if because when you enter a 6 more than one else-if is true; I thought that since the else-if breaks out when finding a true, that this was just as good. What do think?

int hoursOfSleep = 9;

if (hoursOfSleep >= 10 )
{
    Console.WriteLine("Wow! That's a lot of sleep!");
}
else if (hoursOfSleep > 8 )
{
    Console.WriteLine("You should be pretty rested.");
}
else if (hoursOfSleep > 5)
{
    Console.WriteLine("That's not bad.");
}
else if (hoursOfSleep > 4)
{
    Console.WriteLine("Bummer.");
}
else
{
    Console.WriteLine("Oh man, get some sleep!");
}

Aucun commentaire:

Enregistrer un commentaire