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 trial

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
15,052 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
15,052 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
15,052 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!