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 Final

Megan Carlton
Megan Carlton
3,260 Points

what are my compiler errors?

am getting compiler errors on lines 28/29/30. cannot figure this out?!?!?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");

            var entry = Console.ReadLine();

            if (entry == double.Parse(entry))
              {
                keepGoing = false;
              }
            else
            {
                try
                {

                  var number = int.Parse(entry);
                  var go = 0;

                  while (go ++< number)
                  {
                   Console.WriteLine("Yay!");
                  }  
                } 
              }
             catch(FormatException)         
              {
                Console.WriteLine("You must enter a whole number.");
                continue;

              }
        }
    }
}
Megan Carlton
Megan Carlton
3,260 Points

i just tried adding my catch before the else and changed continue to break based on previous answers (including Steven Parkers) but i am still struggling.... :(

1 Answer

Steven Parker
Steven Parker
231,248 Points

I hate spoilers, let's try a few more hints (my previous ones still apply):

  • you assign a variable keepGoing but it is never declared or used (or needed, for that matter)
  • you only need to Parse your input once. And not as a double.
  • you won't need any tests other than the while condition and the try block (no if or else)
  • a catch block must be at the same block level as the corresponding try block
  • you cannot use continue outside of a loop.

You're getting close. In fact, you can pass the challenge without adding anything and just deleting 8 lines.

Megan Carlton
Megan Carlton
3,260 Points

Aha! Thank you Obi-Wan!! have completed the challenge now. thanks again. (i was making it more complicated for myself than it needed to be :) )