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

if/else if/else Print the message from the table when a user enters a number in the corresponding range.

"""C# string input = Console.ReadLine(); int temperature = int.Parse(input); if(temperature < 21) { System.Console.WriteLine("Too cold!") }
else if (temperature >= 21 && temperature <= 22) { System.Console.WriteLine("Just Right."); } else { System.Console.WriteLine("Too hot!"); } """

string input = Console.ReadLine();
int temperature = int.Parse(input);
if(temperature < 21)
 Console.WriteLine("Too cold!")
else if(temperature >= 21 && temperature <= 22)
Console.WriteLine("Just Right.");
Console.WriteLine("Too hot!");

2 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Hi Bacar,

You're code is correct except for one small syntax error. If you click preview in the challenge, it gives you the clue to where the error is:

StudentsCode.cs(13,1): error CS1002: ; expected
Compilation failed: 1 error(s), 0 warnings

As the "; expected" states, you are missing a semicolon for the code block inside the if clause. Once that's put in, your code passes. :thumbsup:

Other than that... Nice Job!! :) :dizzy:

Hi Jason,

Thank you legend, I didn't realise that. Thank you so much for your advise.

Take Care :)