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 trialali raafat
444 Pointscan i get help in variable scoop
i don't know why it keeps giving me an error about input
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
try
{
input = Console.ReadLine();
if (input == "quit")
{
string output = "Goodbye.";
}
else
{
string output = "You entered " + input + ".";
}
}
catch(Exception)
{
Console.WriteLine(output);
}
}
}
}
1 Answer
Steven Parker
231,235 PointsVariables need to be declared before they are used (or as they are initialized).
The error you see about input is because it has not been declared.
Once you fix that, you'll also need to check that variables are declared in the outermost scope in which they are used. Remember you can assign a variable many times, but you should only declare it once.
ali raafat
444 Pointsali raafat
444 Pointshow can i know and how to add one iam confused
Steven Parker
231,235 PointsSteven Parker
231,235 PointsBy "one" ... do you mean declaration?
A simple declaration:
variable_type variable_name; (example:
int jellies;
)A declaration with initialization:
variable_type variable_name = Initial_value; (example:
string food = "doughnut";
)