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#

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");



    }
}

}

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

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");
    }
  }
}

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

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

Thanks!