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

Sam Cottingham
Sam Cottingham
5,064 Points

If/Else If/Else challenge task - Compiler Error?

I'm getting a compiler error of: StudentsCode.cs(18,4): error CS1525: Unexpected symbol `{' StudentsCode.cs(18,5): warning CS0642: Possible mistaken empty statement Compilation failed: 1 error(s), 1 warnings

But I can't see where I've gone wrong or misplaced a { symbol? Am I just being blind?

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

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

1 Answer

Steven Parker
Steven Parker
231,210 Points

:point_right: A simple else statement does not take an expression.

It handles all cases not already done by one of the previous if and else if statements.

For program clarity, you might convert that last expression into a comment (put // in front of it).