I need to input 3 numbers, and then output the highest & lowest of the 3 numbers using IF commands. I have everything working, except I'm getting 1 largest number (correct) and 3 outputs of the lowest number (incorrect). Now I totally understand why they're all being displayed, I just do not know how to fix it. My code, once the integers have been defined by user input, is as follows:
if (num1 > num2 && num1 > num3)
{
Console.WriteLine("Largest Number: " + num1);
}
if (num2 > num3)
{
Console.WriteLine("Smallest Number: " + num3);
}
else
{
Console.WriteLine("Smallest Number: " + num2);
}
and then duplicated 3 times, switching the respective integers. I understand what the issue is, it's that the second if command is correct for all 3 scenarios. I just... don't know how to fix it. I feel like I just need to join these two if statements together somehow but I'm unsure how to do this, or if it's even possible.
Aucun commentaire:
Enregistrer un commentaire