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 Validating Input

Sean Flanagan
Sean Flanagan
33,235 Points

Different error to the one described

Hi.

I have a different error and for a different reason:

Here's my code:

using System; //Using directive: avoids repeating "System".

namespace Treehouse.FitnessFrog
{
  class Program
  {
      static void Main()
      {
        int runningTotal = 0;
        bool keepGoing = true;

        while (keepGoing) {
          // Prompt the user for minutes exercised
          Console.Write("Enter how many minutes you exercised or type \"quit\" to exit: "); //Print             text to screen, keeps cursor at end of line after colon.
          // Write: method name. 
          // Console: name of class that contains method.
          // System: namespace that contains class.
          // Namespace.ClassName.MethodName(parameterType parameterName);
          string entry = Console.ReadLine(); //ReadLine reads one line at a time from the console.

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

            if (minutes <= 0)
            {
              Console.WriteLine(minutes + " is not an acceptable value.");
              continue;
            }
            else if (minutes <= 10)
            {
              Console.WriteLine("Better than nothing!");
            }
            else if (minutes <= 30)
            {
              Console.WriteLine("Way to go!");
            }
            else if (minutes <= 60)
            {
              Console.WriteLine("You must be a ninja in training!");
            }
            else
            {
              Console.WriteLine("Okay, now you're just showing off!");
            }

            runningTotal = runningTotal + minutes;

            // Add minutes exercised to total.
            // Display total minutes exercised on-screen.
            //WriteLine writes one line at a time to the console.

            Console.WriteLine("You've entered " + runningTotal + " minutes."); //Plus operator                   concatenates strings.
          }
          // Repeat until user quits.
        }
        Console.WriteLine("Goodbye");
      }
  }
}

Error message:

(1,14): error CS1525: Unexpected symbol `Program'                                                
(1,33): error CS1525: Unexpected symbol `Program' 

Snapshot: https://w.trhou.se/2uhkr2ra1c

Thanks in advance for any assistance. :)

Steven Parker
Steven Parker
231,248 Points

What is it you do to get this error? I made a fork (copy) of your snapshot, then built it using "mcs Program.cs", and then ran it using "mono Program.exe". The program compiled without errors and then ran as expected.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Steven. Thanks for chiming in. I appreciate your help. I don't know what's causing this problem. I've looked at the code but it's like looking for a needle in a haystack. From what you're saying, it sounds as if my program shouldn't have thrown any exceptions. If that's the case, I have to wonder if there's a technical problem with the console. Maybe I'd better contact Support. Thanks. :)

Lewis Cowles
Lewis Cowles
74,902 Points

I too can confirm the example compiles and runs using positive integer input or quit; it could be as simply as a failed HTTP request to the Treehouse servers; or the VM you were connected to having a config issue; Definitely reach out to the Treehouse team, as the code works in WorkSpaces.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Lewis. Thanks for responding to my request. I emailed Support yesterday. There was only one employee there. They said there were no teachers available during weekends and if the problem still hasn't been resolved in a couple of days then to contact them again and they'd bring a teacher in. I'm going to keep trying. Cheers! :)

Lewis Cowles
Lewis Cowles
74,902 Points

Yeah, sorry to hear about the trouble you are having; but the teachers need to have down-time too so that they remain hyped and continue to deliver great courses, great value etc; think about the cost of Treehouse (balanced group) vs personalized training @ minimum £500/day and you'll see the value

Stéphane Diez
Stéphane Diez
19,350 Points

chech your Filename. maybe?

1 Answer

Sean Flanagan
Sean Flanagan
33,235 Points

It seems to be working okay now. Thank you all. :)