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 King
James King
3,670 Points

I can't figure out why my answer isn't correct.

I have gone over this as many ways as I can think of and I'm still getting errors...please help me.

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

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

2 Answers

Steven Parker
Steven Parker
231,248 Points

A plain "else" statement (the last one) does not take a conditional expression. It doesn't need one since it handles any case not already covered by the "if/else if" chain.

else
{
    Console.WriteLine("Too hot!");
}
James King
James King
3,670 Points

Thank you! I actually figured that out very shortly after I posted this :)

James King
James King
3,670 Points

Hey Steve, are you guys available for questions basically 24/7?

Steven Parker
Steven Parker
231,248 Points

I'm not sure what you mean by "you guys". I'm another student like yourself, so it's "us guys". :smile:

And I may be on frequently, but definitely not "24/7"! But there's a lot of students, and from many countries, so there's a chance of a quick reply from someone at nearly any time.