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

What I am doing wrong?

What I am doing wrong here?

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

if(temperature > 21)
{
Console.WriteLine(" Too cold! ");

}
else if(temperature  => 22 )

{
Console.WriteLine(" Just right. ");

}
else 

{
Console.WriteLine(" Too hot! ");
}

3 Answers

Here is a different way to do it, take a look and see if you can follow the logic of the if-else statements:

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

        if(temperature <= 21)
        {
        Console.WriteLine(" Too cold! ");

        }
        else if(temperature == 22 )

        {
        Console.WriteLine(" Just right. ");

        }
        else 

        {
        Console.WriteLine(" Too hot! ");
        }

Less than 21° Too cold! 21° to 22° Just right. Greater than 22° Too hot!

In your case 21 ll print as too cold!Am i right?

Also can you please tell me what is wrong with my code?I am receiving the following error;

\tudentsCode.cs(10,4): error CS0136: A local variable named temperature' cannot be declared in this scope because it would give a different meaning totemperature', which is already used in a `parent or current' scope to denote something else Compilation failed: 1 error(s), 0 warnings

Any idea?

The error displays because in your code you are using => which is a way to define a function, use >= instead.

Yes, you are correct about the logic, I did not look at the original question, only worked off your code. I believe you can tweak the code to make it do what you want to do, you are 90% there. Cheers.