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 trialEdward Hwang
Courses Plus Student 1,047 PointsCompile error: The name 'Console' does not exist in the current context
I ran my source code for the FitnessFrog app and the compiler said that the name 'Console' doesn't exist in the current context. What does this mean and why does this happen? I'll put the code below if it can be of help.
class Program
{
static void Main()
{
int runningTotal = 0;
bool keepGoing = true;
while(keepGoing)
{
//Prompt the use for minutes exercised
Console.Write("Enter how many minutes you exercised or type /"quit/" to exit: ");
string entry = Console.ReadLine();
if (entry == "quit")
{
keepGoing = false;
}
else
{
int minutes = int.Parse(entry);
runningTotal = runningTotal + minutes;
//Repeat until the user quits
Console.WriteLine("You've entered " + runningTotal + " minutes");
}
Console.WriteLine("Goodbye");
}
}
}
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! I received your request for assistance. Ben Reynolds is correct. You're going to need to change those slashes. But that's not why you're getting your current error.
The reason you're getting your current error is that you've not included the namespace nor told it using System
. The Console
class belongs to to the System
class. Without having imported or using a class where Console
is defined, the compiler will have no idea what you mean. Take a look at the code posted in the "Teacher's Notes". Your code should start with using System;
and your class should be nested inside the namespace.
using System;
namespace Treehouse.FitnessFrog
{
// Your Program class goes here
}
Hope this helps!
Edward Hwang
Courses Plus Student 1,047 PointsTwo of the curly brackets got out of the code example itself - sorry about that. Please keep this in mind and don't think of it as a programming error! I did add those brackets to the code in my workspace.
Ben Reynolds
35,170 PointsHi Edward,
I suspect the problem might be coming from the first line in the while loop where it says /"quit/"
The escape character should be a backslash, not a forward slash, so try replacing that part with:
\"quit\"
Let me know if this helps, Ben
Edward Hwang
Courses Plus Student 1,047 PointsIt wasn't the main reason for my error, but it still fixed a minor code error. Thanks, Ben!
Edward Hwang
Courses Plus Student 1,047 PointsEdward Hwang
Courses Plus Student 1,047 PointsThanks! Now my program is running properly!