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.

Riley Sutton
889 PointsC# Compiler error
New to programming. I cant seam to find out why im getting the following an error here.
StudentsCode.cs(18,2): error CS1525: Unexpected symbol `{' StudentsCode.cs(18,3): warning CS0642: Possible mistaken empty statement Compilation failed: 1 error(s), 1 warnings
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!");
}
2 Answers

Afrid Mondal
6,255 PointsHey Riley, you are doing great. But, remember never put condition on else block, because it's statement going to execute if any other statement is not matched the condition. I correct your code and it will run...
string input = Console.ReadLine();
int temperature = int.Parse(input);
if(temperature < 21) {
Console.WriteLine("Too Cold!");
} else if(temperature == 21 || temperature == 22){
Console.WriteLine("Just right.");
} else {
Console.WriteLine("Too hot!");
}

Steven Parker
221,292 Points Just convert the unneeded test after the else into a comment:
if (temperature < 21)
Console.WriteLine("Too Cold!");
else if(temperature <= 22)
Console.WriteLine("Just right.");
else //(temperature > 22)
Console.WriteLine("Too hot!");
It fixes it, and it's a good programming practice. (Also for brevity I removed the braces - they aren't needed when there's only one statement anyway).

Riley Sutton
889 PointsThank you Steven!
Jordan Power
6,503 PointsJordan Power
6,503 PointsThink of the else block to be the default code block that runs when none of the above conditions are met (AKA, none of the conditional statements return true!) Afrid was spot on with this, your error is due to the conditional statement you wrote after the else keyword.
Riley Sutton
889 PointsRiley Sutton
889 PointsThank you!