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

ali raafat
ali raafat
444 Points

can you help me in this if/else/if

i need help to write 21 to 22

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

if(temperature <=21)
{
    Console.WriteLine(" Too cold ");
}
else if( temperature >=21 <=22) 
        {
           Console.WriteLine("Just right");
        }
        else
        {
            Console.WriteLine("too hot ");
        }

1 Answer

Steven Parker
Steven Parker
229,771 Points

:point_right: Check the number ranges and your messages.

Remember, anything below 21 is "Too cold!", so instead of comparing "less than or equal 21" (temperature <= 21), you should check only for "less than 21 (temperature < 21)". On the other hand, "Just right." includes 22, so for the next test you might use "less than or equal 22" (temperature <= 22). Then the plain else will take care of the rest.

You should also be careful to use the exact strings the challenge asks for (and will be expecting). Be sure to use capital letters and punctuation exactly as shown, and no extra spaces. String comparisons are very picky!