Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perfect if / else if / else

Angus Eliott
Angus Eliott
3,793 Points

if else problem

Hey, could someone help me with this, please ?

string input = Console.ReadLine();
int temperature = int.Parse(input);
if(temperature =< 21) {
    System.Console.Writeline("Too Cold!");
else if (temperature => 21 == > 22){
    System.Console.WriteLine("Just right.");
else if (temperature => 22){
    System.Console.WriteLine("Too hot!");

1 Answer

Ben Reynolds
Ben Reynolds
35,170 Points
  1. The expression "greater/less than or equal to" has the angle bracket before the equals sign (watch out for =< vs <=)
  2. The WriteLine method needs to be written with a capital W and L.
  3. The "else if" condition should read like this: "temperature is greater than or equal to 21 AND temperature is less than or equal to 22."
  4. The second "else if" block can simply be an "else" block without a condition or parentheses. This block will just catch everything else that isn't caught by the "if" or "else if" conditions.