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

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
229,732 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.