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 trial

C# C# Basics (Retired) Perfect if / else if / else

Brandon Hartman
Brandon Hartman
8,032 Points

This code is getting to me!

The following table describes my room temperature preferences. Print the message from the table when a user enters a number in the corresponding range. For example, if temperature is 21 the code should print "Just right." to the screen.

Temperature (°C) Message

Less than 21° Too cold!

21° to 22° Just right.

Greater than 22° Too hot!

Dane Parchment
Dane Parchment
Treehouse Moderator 11,077 Points

Show us the code that you are having trouble with. From here it seems like you are asking for somebody to code it for you. So show us the code so that we can be of some help.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Brandon. It's a good habit to always send the code if you get stuck. If you wrap the code in two trios of backticks (```) we should be able to help. Also if you click the snapshot option at the top right of your work space (the camera icon) and paste the link to the snapshot in your message, that'll give us something else to work with.

Watching the video Michael recommended will certainly help you.

2 Answers

Also be conscious of the punctuation. Here is my working code. Make sure they match exactly what the problem is looking for :) Happy Coding

string input = Console.ReadLine();
int temperature = int.Parse(input);

if (temperature < 21)
{
  Console.WriteLine("Too cold!");
}
else if (temperature > 22)
{
  Console.WriteLine("Too hot!");
}
else 
{
  Console.WriteLine("Just right.");
}
Jonathan Wade Jr
Jonathan Wade Jr
1,051 Points

I had the same issue. Thanks for helping me figure that out

You should review video "if/else if /else starting at minute 3 (https://teamtreehouse.com/library/c-basics/perfect/if-else-if-else).

Example of code:

if (temperature < 21)
{
// Too Cold!
}
else if (temperature > 22)
{
// Too Hot!
}
else 
{
// Just Right!
}