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#

I'm typing numbers out (int and double) and there is a problem

I'm typing out int and double numbers and it's printing out the text it should be but its also printing out 0 with it like I have not typed in anything.

using System;

namespace Treehouse.FitnessFrog
{
  class Program
  {
      static void Main()
      {
          double runningTotal = 0;
          bool keepGoing = true;
          while (keepGoing) 
        {
            // Prompt the user for minutes exercised
            Console.Write("Enter how many minutes you have exercised or type \"quit\" to exit: ");

              string entry = Console.ReadLine();

              if(entry.ToLower() == "quit")
              {
                 keepGoing = false;
              }
              else
              {                
                  try
                  {
                     double minutes = double.Parse(entry);

                     if(minutes <= 0)
                        {
                          Console.Write(minutes + " is not an acceptable value. ");
                          continue;
                        }

                      else if(minutes <= 10)
                      {
                          Console.Write("Better than nothing I suppose. ");
                      }
                      else if(minutes <= 30)
                      {
                          Console.Write("Hell yeah! ");
                      }
                      else if(minutes <= 60)
                      {
                          Console.Write("Am I seeing a warrior in training? ");
                      }
                      else
                      {
                          Console.Write("Stop showing off! But don't stop exercising though, it's     good for you! ");

                        runningTotal = runningTotal + minutes;

                      }
                  }
                   catch(FormatException)
                  {
                      Console.Write("That is not a valid input. ");
                      continue;
                   }

            // Add minutes exercised to total
            // Display total minutes exercised to the screen#
            Console.WriteLine("You've entered " + runningTotal + " minutes");
            }
            // Repeat until user quits 
        } 
            Console.WriteLine("Goodbye");
      }
  }
}

1 Answer

Steven Parker
Steven Parker
231,110 Points

As it is now, the "minutes" are only added to "runningTotal" when they are more than 60 (and it displays "Stop showing off!").

But you probably want to move that statement outside of the conditional so that it is done for all values.

A good place to put it would be right after the line with this comment:

            // Add minutes exercised to total

Okay thanks. Also i appreciate that you're dedicating time to helping people on here :)