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#

Bryony Stewart
Bryony Stewart
1,230 Points

Parse returning 0

I have an int runningTotal = 0; that still returns 0 after a value as been entered.

Bryony Stewart
Bryony Stewart
1,230 Points

using System; namespace myPro {

class Program 
{


         static void Main()
         {
             int runningTotal = 0; 
             bool keepGoing = true;


                  while(keepGoing)
                  {      Console.Write("please enter the number of minutes you would like, type \"quit\" to exit: ");
                         string entry = Console.ReadLine();

                         Console.WriteLine("you have enterd "+ runningTotal +" minutes");  
                              if (entry == "quit" )
                              {
                                  keepGoing = false; 

                              }
                              else 
                              {

                                  int minutes = int.Parse(entry);
                                  runningTotal = runningTotal + minutes;
                                   if(runningTotal <= 0)
                                   {

                                      Console.WriteLine("This is not a vaild entry!");


                                   }
                                   else if (runningTotal <= 30)
                                   {

                                      Console.WriteLine("This is a good starting point");
                                   }
                                   else if (runningTotal <= 60)
                                   {
                                       Console.WriteLine("Now you are pushing the limit");
                                   }
                                   else 
                                   {           
                                         Console.WriteLine("Now you are just showing off"); 
                                   }


                              }





                  }


                       Console.Write("Goodbye"); 




          }







         }             



}

We need an example of your input and how it's assigned to runningTotal.

edited: Looks like you were adding your example as I typed this message.

1 Answer

Try moving the Console.WriteLine down below your if statement. Your showing runningTotal before you parse the entry and add it to runningTotal.