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 trialbluelearner
Courses Plus Student 2,492 PointsCould 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
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
231,275 PointsA plain "else" doesn't take an expression, not even an empty one. So just don't put parentheses after it.
Fredrik Rönnehag
2,342 PointsStudentsCode.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.