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# C# Basics (Retired) Perfect if / else if / else

I need the correct code! I can't seem to debug this. Can someone help? using System;

using System;

namespace Treehouse.FitnessFrog//namespace
{
  class Program//class
  {
      static void Main()//method
      {

        int runningTotal = 0;
        bool keepGoing = true;

        while(keepGoing)
        {
          //prompt user for minutes exercisesd
          Console.Write("Enter how many minutes you exercised or type \"quit\" to enxt: ");
          string entry = Console.ReadLine();

          if (entry == "quit")
          {
            keepGoing = false;
          }
          else
          {

          int minutes = int.Parse(entry);
          if(minutes <= 10)
          {
            Console.WriteLine("Better than nothing");
          }
            else if(minutes<=30)
            {
              Console.WriteLine("Way to go");
            }
            else if(minutes <=60)
            {
              Console.WriteLine("Pizza tonight!");
            }
            else
            {
              Console.WriteLine("you are just showing off!);
             }                   

          //add minutes exd to total
          runningTotal = runningTotal + minutes;

          Console.WriteLine("You entered " + runningTotal + " minutes");
          //Display total minutes exercised to the screen




          //repeat until user quits

        }
     }

}

(Edited by BothXP to add the markdown formatting)

3 Answers

Hi Jon,

When I try and compile your code I get:

Program.cs(41,60): error CS1010: Newline in constant
Program.cs(42,13): error CS1525: Unexpected symbol `}', expecting `)' or `,' 
Program.cs(42,14): error CS1002: ; expected
Program.cs(57,246): error CS1525: Unexpected symbol `end-of-file'

So lets start at the top. It is indicating a issue on line 41, at around character 60. Looking at that line I can see that you have a " missing from the end of your text.

If you fix that and then compile again then you will get:

Program.cs(57,246): error CS1525: Unexpected symbol `end-of-file'

That's normally a good hint that you might be missing some }. If you check back through you opening and closing curly brackets you should be able to see that you are missing 2 } from the end of the file.

Once you put those in we get:

using System;

namespace Treehouse.FitnessFrog//namespace
{
  class Program//class
  {
      static void Main()//method
      {

        int runningTotal = 0;
        bool keepGoing = true;

        while(keepGoing)
        {
          //prompt user for minutes exercisesd
          Console.Write("Enter how many minutes you exercised or type \"quit\" to exit: ");
          string entry = Console.ReadLine();

          if (entry == "quit")
          {
            keepGoing = false;
          }
          else
          {

          int minutes = int.Parse(entry);
          if(minutes <= 10)
          {
            Console.WriteLine("Better than nothing");
          }
            else if(minutes<=30)
            {
              Console.WriteLine("Way to go");
            }
            else if(minutes <=60)
            {
              Console.WriteLine("Pizza tonight!");
            }
            else
            {
              Console.WriteLine("you are just showing off!");
             }                   

          //add minutes exd to total
          runningTotal = runningTotal + minutes;

          Console.WriteLine("You entered " + runningTotal + " minutes");
          //Display total minutes exercised to the screen




          //repeat until user quits

        }
     }
    }
  }
}

and that code appears to compile and run.

I hope that helps.

(Update: and I see that Ken beat me to it :-) )

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jon;

Welcome to Treehouse!

At the moment I notice you don't have a closing quote at the end of:

Console.WriteLine("you are just showing off!);

And, if the above code is accurate, you are missing two closing brackets, one for your class and one for your namespace.

With those syntax changes things seem to work as desired. You also have a typo in the word exit on line 16.

Happy coding,
Ken

Thanks!! i've got it now ... I was having trouble moving forward in the C# course.. Much appreciated.