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

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.