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 trialEwa Sidor
1,084 PointsCould you check my work and tell me what is wrong with my code?
I do not understand whats the error message. It doesn't make any sens to me.
string input = System.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!");
}
```Error :
StudentsCode.cs(19,4): error CS1525: Unexpected symbol `{'
StudentsCode.cs(19,5): warning CS0642: Possible mistaken empty statement
Compilation failed: 1 error(s), 1 warnings
Ewa Sidor
1,084 PointsStudentsCode.cs(19,4): error CS1525: Unexpected symbol `{' StudentsCode.cs(19,5): warning CS0642: Possible mistaken empty statement Compilation failed: 1 error(s), 1 warnings
2 Answers
andren
28,558 PointsThe problem is that else
statements does not accept conditions. An else
statement is automatically executed if the statements above it are not run. In this case you can simply remove the condition and your code will work fine since the previous statements cover temperatures equal to and below 22. Like this:
string input = System.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
{
System.Console.WriteLine("Too hot!");
}
Ewa Sidor
1,084 PointsThank you. It works now :)
Kyle Southerland
UX Design Techdegree Student 11,117 PointsKyle Southerland
UX Design Techdegree Student 11,117 PointsWhat's the actual error message you are receiving?