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 trialDominick Bartenope
2,092 PointsNot quite sure what I'm doing wrong
I declared input as a string variable and then declared the output variable in the main method but I don't understand why it is coming up as incorrect
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
string input = Console.ReadLine();
string output;
if (input == "quit")
{
string output = "Goodbye.";
}
else
{
string output = "You entered " + input + ".";
}
Console.WriteLine(output);
}
}
}
3 Answers
Steven Parker
231,248 PointsA variable should only be declared once. It can be assigned many times, but in a plain assignment the name will not be preceded by the type.
Ben Reynolds
35,170 PointsSince you've declared "output" in Main and made it a string, you don't need to use "string" before the variable name in the if and else blocks. It thinks you're trying to declare a new variable called output in each of those lines but it already exists.
Dominick Bartenope
2,092 PointsThanks Steven, that helped me figure it out. Cheers!