C# C# Basics (Retired) Perform if / else

Edward Hwang
PRO
Edward Hwang
Pro Student 1,047 Points

Compile 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
STAFF
Jennifer Nordell
Treehouse Staff

Hi 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! :sparkles:

Edward Hwang
Edward Hwang
Pro Student 1,047 Points

Thanks! Now my program is running properly!

Edward Hwang
PRO
Edward Hwang
Pro Student 1,047 Points

Two 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
Ben Reynolds
35,167 Points

Hi 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
Edward Hwang
Pro Student 1,047 Points

It wasn't the main reason for my error, but it still fixed a minor code error. Thanks, Ben!