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

Not sure whats wrong.

string input = Console.ReadLine(); int temperature = int.Parse(input);

if(temperature <= 21) { Console.WriteLine("Too cold!"); } else if (temperature => 21 && <= 22) { Console.WriteLine("Just right."); } else if(temperature > 22) { Console.WireLine("Too hot!"); }

CodeChallenge.cs
string input = Console.ReadLine();
int temperature = int.Parse(input);

if(temperature <= 21)
{
Console.WriteLine("Too cold!");
}
else if (temperature => 21 && <= 22)
{
Console.WriteLine("Just right.");
}
else if(temperature > 22)
{
Console.WireLine("Too hot!");
}

5 Answers

Hi Matt,

Have a think about:

if(temperature < 21){
  Console.WriteLine("Too cold!");
} else if (temperature <= 22){
  Console.WriteLine("Just right.");
} else {
  Console.WriteLine("Too hot!");
}

Make sure that you are only getting the "Too cold!" message if the temperature is less than 21 (not also equal to it). You only need 1 'else if' and you don't need to use the && because you will only get to this test if the temperature is 21 or above due to the test in the original 'if'. Then at the end you only need to use an 'else'.

This is the error I get. No clue what it means. A local variable named setting' cannot be declared in this scope because it would give a different meaning tosetting', which is already used in a `parent or current' scope to denote something else

if (temperature >= 21 && temperature <= 22)
{
  Console.WriteLine("Just right.");
}

You're using => which is a Lambda operator which doesn't mean what you intend. Also you need to have the temperature compared on both sides of the &&

OK thanks!

Thanks for the explanation.