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#

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.