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

James Khamsan
James Khamsan
721 Points

The following table describes my room temperature preferences. Print the message from the table when a user enters a num

What went wrong?

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

if(temperature <=21) { Console.WriteLine("Too cold!)"); } else if(temperature <=21 to 22) { Console.WriteLine("Just right."); } else if(tepmerature >=22) { 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 to 22)
{
    Console.WriteLine("Just right.");
}
else if(tepmerature >=22)
{
    Console.WriteLine("Too hot!");
}

1 Answer

Antonio De Rose
Antonio De Rose
20,885 Points
string input = Console.ReadLine();
int temperature = int.Parse(input);

if(temperature <=21) // you just have go well aligned with the question should it be less or less than equal
{
    Console.WriteLine("Too cold!)");
}
else if(temperature <=21 to 22) //this is how you not combine 2 comparison's
{
    Console.WriteLine("Just right.");
}
else if(tepmerature >=22) //should it be greater or greater than equal to
{
    Console.WriteLine("Too hot!");
}

Couple of things I noticed: little things like your <= on if #1, read carefully what the instructions say (less than, not less than equal to)... If #2, it'll never pass, look at your first condition and look at the condition on if #1, also, "to" os not a thing in C# (look for something along the lines of "and" (also not a thing, there are symbols)... If #3, look at your variable name, and, as Antonio said, again look at what the instructions say (greater than... I'm saying this because it'll always say wrong if we let be like that, it's very picky)