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 trialNick Torchio
912 PointsDifficulty with tracking compiler errors.
My main question is if there is an issue with the compiler errors being shown on the wrong lines. For the past few challenges I've had compiler errors show up and they are always indicated on lines that I have no code written on. For example this challenge tells me that I have errors on line 22, but my code ends at 19. As an additional question since I can't track my errors, what am I doing wrong here?
string input = Console.ReadLine();
int temperature = int.Parse(input);
if(temperature <= 20)
{
Console.WriteLine("Too cold!");
}
else if(temperature == 21);
{
Console.WriteLine("Just right.");
}
else if(temperature == 22);
{
Console.WriteLine("Just right.");
}
else if(temperature >= 23)
{
Console.WriteLine("Too hot!");
}
1 Answer
andren
28,558 PointsThe problem with your code is that you have a closing ;
(semicolon) following the parenthesis of your else if statements, which should not be there. By placing a ;
(semicolon) there you tell C# that the else if block is finished when in fact it has not even started. That's why the compiler error mentions "empty statements".
If you remove them then your code will work.
As for your other question due to the way your code is run in these challenges the line numbers are often not quite accurate. They are offset slightly due to the fact that Treehouse usually does not just run your code by itself, it usually loads a code checker program that in turn loads your code. This is done to have more control over how your program behaves and to make it easier to test that it actually acts the way it should.