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 trialDavid Murumbi
1,442 PointsWhat 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");
}
}
}
2 Answers
Kevin Gates
15,053 PointsThe 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
1,442 Pointsoops! I guess it was just a silly mistake... Thanks a lot appreciate the fast response!
Kevin Gates
15,053 PointsNo worries. You're welcome. @David Murumbi, would you mind marking my answer as "Best Answer" so that others can benefit more easily?
Thanks!
Kevin Gates
15,053 PointsKevin Gates
15,053 PointsI reformated your code to read more easily: