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 trialAmmar Fatihallah
7,417 PointsGetting a CS0019 error, don't know why.
Can anybody tell me why do I keep getting this error even though the temperature variable is set to int.
string input = Console.ReadLine();
int temperature = int.Parse(input);
if (temperature < 21) {
Console.WriteLine("Too cold!");
}
else if (21 < temperature < 22) {
Console.WriteLine("Just right.");
}
else if (temperature > 22) {
Console.WriteLine("Too hot!");
}
2 Answers
Tizmiz Tizzer
1,040 PointsTry changing else if (21 < temperature < 22) to else if (temperature == 21 || temperature == 22)
This should work since you are comparing the two values (21 and 22) and making sure one or the other is == to temperature, and if they aren't you will move down to the next if else/else statement.
Jon Wood
9,884 PointsIn this if statement:
else if (21 < temperature < 22)
You need to compare each value to the temperature
variable and use the and (&&
) operator on it, like this:
else if (21 < temperature && temperature < 22)
Ammar Fatihallah
7,417 PointsThanks for your help. I tried to use the && operator but the challenge won't complete without some errors. So I tried the || operator and it passed. Thank you though for your help!
Jon Wood
9,884 PointsHeh, my bad. I wasn't even thinking about the logic. I was just making sure I got that error fixed :p
Ammar Fatihallah
7,417 PointsHaha no problem man, thanks for the help :)
Jon Wood
9,884 PointsAnd I just learned something from you! I had no idea you could do that in Python. I'm learning that, myself. :)
Ammar Fatihallah
7,417 PointsAmmar Fatihallah
7,417 PointsThank you! I kinda didn't understand it but then I twisted my mind and figured it out. I come from a python background so I hope you know why I did that lol.
Tizmiz Tizzer
1,040 PointsTizmiz Tizzer
1,040 PointsI started with python as my first language. I've made the same mistake before too, glad I could help!