Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!"); } """

CodeChallenge.cs
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.");
}
else
{
Console.WriteLine("Too hot!");
}

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,623 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 :)