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 trialmishari alabduljader
2,133 PointsC# 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
Python Web Development Techdegree Student 38,322 PointsThe 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.");
}
mishari alabduljader
2,133 Pointsthanks alot