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

Scope rules C#

I don't fully understand what I am meant to be doing here, I understand the scope rules and have attempted to declare the variable outside the if/else under the main method but it still doesn't seem to work.

Program.cs
using System;

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

            if (input == "quit")
            {
              output = "Goodbye.";
            }
            else
            {
                output = ("You entered " + input + ".";)
            }

            Console.WriteLine(output);
        }
    }
}
Matti Mรคnty
Matti Mรคnty
5,885 Points

Actually, your only problem here is a wrong placement of a semicolon.

          output = ("You entered " + input + ".";)

That semicolon should be outside the brackets, like so:

          output = ("You entered " + input + ".");

Other than that, the scope seems to check out! So keep on working on it!

1 Answer

Stuart Wright
Stuart Wright
41,118 Points

You have the right idea and you've understood the scope issue correctly. You just need to fix your syntax - there shouldn't be any parentheses in this statement:

output = ("You entered " + input + ".";)

Remove them and you're good to go.