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 trialRachael Helsel
Courses Plus Student 490 PointsI don't understand why input is not recognized when it's in the broader scope...
I'm still getting the error that input isn't declared, but it's at the very beginning of the Main method...so I'm not clear why.
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
Steven Parker
231,248 PointsThe variable input
is only being assigned at the moment.
To be declared, it would need to be preceded by a type, or at least the keyword "var".
Also, if you move the WriteLine into the else block, you are changing the intent of the program. To preserve the original intent you'll need to make sure output
is only declared once, and in the outermost scope where it used.
Jon Wood
9,884 PointsJon Wood
9,884 PointsI think
input
needs to be declared. Tryvar input = Console.ReadLine():
.