C# C# Basics Perfect if / else if / else

Dean Tinashe Katsaura
Dean Tinashe Katsaura
288 Points

The use of if,else if and else

How to use if,else if and else to compare values of temperature

CodeChallenge.cs
string input = Console.ReadLine();
int temperature = int.Parse(input);
if(temperature < 21)
    { 
    System.Console.WriteLine("Too cold!");
     }
else if(temperature <= 22)
    { 
    System.Console.WriteLine("Just right.");
     }
else()
    {  
    System.Console.WriteLine("Too hot!");
    }

1 Answer

Antonio De Rose
Antonio De Rose
18,529 Points
string input = Console.ReadLine();
int temperature = int.Parse(input);
if(temperature < 21)
    { 
    System.Console.WriteLine("Too cold!");
     }
else if(temperature <= 22)
    { 
    System.Console.WriteLine("Just right.");
     }
else()//why do you need this paranthesis
    {  
    System.Console.WriteLine("Too hot!");
    }