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

Chris Murphy
Chris Murphy
4,391 Points

if/else if/else issue

I get an error that states my '{' is an unexpected symbol. I'm not sure why my code is not working.

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

if (temperature < 21)
{
    System.Console.WriteLine("Too cold!");
}

else if (temperature >=21)
{
    System.Console.WriteLine("Just right.");
}

else (temperature < 22)
{
    System.Console.WriteLine("Too hot!");
}

An "else" statement doesn't take no conditions... hence, your last statement cannot have a "(temperature < 22)". Take it off.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Uchechukwu Okereke-Ezih is correct. Else statements do not take a condition. They are used when everything else fails. However, it's important to note that you have some logic problems in your solution. It wants every temperature over 22 to print "Too hot!". But it wants both temperatures 21 and 22 to print out "Just right." If we were to remove the condition causing your compiler error right now, and send in temperature 100... we'd get a print out of "Just right." Because you've said anything greater than or equal to 21 should be "Just right." Try rethinking this, and give it another shot with these hints. If you still need further assistance, let us know! :sparkles: