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 Variable Scope

Not sure how to make this compile

Need to make this compile, but there is an error related to variable scope. Where can I move the declaration of input?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            
            input = Console.ReadLine();

            if (input == "quit")
            {
                string output = "Goodbye.";
            }
            else
            {

                string output = "You entered " + input + ".";
            }

            Console.WriteLine(output);
        }
    }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Well, let's start with the first problem you're having: the declaration of the input variable. There is something incorrect about that declaration. There's no data type.

Once you fix that, you'll see that there are other errors regarding the output variable. Might I suggest changing the name of that variable to something else and making a declaration of it where your input is but set to an empty string? :smiley:

I hope these hints will help, but let me know if you're still stuck! :sparkles:

Adam Bader
Adam Bader
4,811 Points

It took me ONE HOUR to figure this out!!!! Thanks :) haha

Caio Viana
Caio Viana
2,889 Points

I was stuck at this, but I did what you said about the input type for the output, I just put the Console.WriteLine(output); inside of the if/else statements

didnt make a declaration of the variable...and it worked

am I wrong?