Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C#

David Murumbi
David Murumbi
1,442 Points

What is wrong with my code??? Error: ... runningTotal does not exist in this context

using System;

namespace Treehouse.FitnessFrog

{ class Program { static void Main() { int runnningTotal = 0; bool KeepGoing = true;

        while (KeepGoing)
        {    
            Console.Write("Enter the number of minutes you have exercised or type 'quit' to exit:  ");
            string input = Console.ReadLine();

            if (input == "quit")
            {
               KeepGoing = false;

            }

            else
            {

                int minutes = int.Parse(input);
                runningTotal = runningTotal + minutes;


                Console.WriteLine("You've exercised for " + runningTotal + "   minutes"); 
            }




        }

        Console.ReadLine("GoodBye");



    }
}

}

Kevin Gates
Kevin Gates
14,887 Points

I reformated your code to read more easily:

using System;

namespace Treehouse.FitnessFrog
{ 
 class Program 
 { static void Main() 
  { int runnningTotal = 0;
    bool KeepGoing = true;

        while (KeepGoing)
        {    
            Console.Write("Enter the number of minutes you have exercised or type 'quit' to exit:  ");
            string input = Console.ReadLine();

            if (input == "quit")
            {
               KeepGoing = false;
            }
            else
            {
                int minutes = int.Parse(input);
                runningTotal = runningTotal + minutes;
                Console.WriteLine("You've exercised for " + runningTotal + "   minutes"); 
            }
        }

        Console.ReadLine("GoodBye");
    }
  }
}

2 Answers

Kevin Gates
Kevin Gates
14,887 Points

The reason it's wrong is the first "runningTotal" is misspelled and you have 3 n's.

Should be this:

using System;

namespace Treehouse.FitnessFrog
{ 
 class Program 
 { static void Main() 
  { int runningTotal = 0;
    bool KeepGoing = true;

        while (KeepGoing)
        {    
            Console.Write("Enter the number of minutes you have exercised or type 'quit' to exit:  ");
            string input = Console.ReadLine();

            if (input == "quit")
            {
               KeepGoing = false;
            }
            else
            {
                int minutes = int.Parse(input);
                runningTotal = runningTotal + minutes;
                Console.WriteLine("You've exercised for " + runningTotal + "   minutes"); 
            }
        }

        Console.ReadLine("GoodBye");
    }
  }
}
David Murumbi
David Murumbi
1,442 Points

oops! I guess it was just a silly mistake... Thanks a lot appreciate the fast response!

Kevin Gates
Kevin Gates
14,887 Points

No worries. You're welcome. @David Murumbi, would you mind marking my answer as "Best Answer" so that others can benefit more easily?

Thanks!