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# if else challenge error

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

//here is my code for the challenge:
/////////////////////////////////////////////
//Temperature (°C) Message
//Less than 21°    Too cold!
//21° to 22°  Just right.
//Greater than 22° Too hot!
//////////////////////////////////////////////


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

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

2 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,319 Points

The problem is your else-statement - else-statements does not like to get a condition.

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

I would also take a look at the conditions passed to the if and else if statement.

if(temperature < 21) // if the temperature is LESS than 21
{
    System.Console.WriteLine("Too cold!");
}
else if(temperature < 22) // if the temperature is LESS than 22
{
    System.Console.WriteLine("Just right.");
}

thanks alot