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

Could someone tell me what is wrong in my answer?

My answer to the challenge:

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

if(temperature <= 20) { System.Console.WriteLine("Too cold!");
} else if(temperature < 23) { System.Console.WriteLine("Just right."); } else() { System.Console.WriteLine("Too hot!"); }

The error I get:

StudentsCode.cs(18,13): error CS1525: Unexpected symbol `)' StudentsCode.cs(18,14): warning CS0642: Possible mistaken empty statement Compilation failed: 1 error(s), 1 warnings

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

if(temperature <= 20)
{
    System.Console.WriteLine("Too cold!");   
}
else if(temperature < 23)
{
    System.Console.WriteLine("Just right.");
}
else()
{
    System.Console.WriteLine("Too hot!");
}

2 Answers

Steven Parker
Steven Parker
215,939 Points

A plain "else" doesn't take an expression, not even an empty one. So just don't put parentheses after it.

Fredrik Rönnehag
Fredrik Rönnehag
2,342 Points

StudentsCode.cs(18,13): error CS1525: Unexpected symbol `)'

You have the explanation and the line of error right there. Else doesn't have any input paremeters. Remove the parentheses.