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

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,882 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)