Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect Final

Archie Byard
Archie Byard
774 Points

The Code Challenge is saying my code doesn't work when it does

I have been writing programs in Workspaces and then putting them into the Code Challenge as I find Workspaces easier to work with.

However having spent about an hour on the Final Code Challenge I finally cracked it and wrote a working code. However, when I entered it into the Code Challenge it says that Task 1 is no longer working; but it does.

This is really frustrating as I am unable to complete this course.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {



         while(true)
         {
         Console.Write("Enter the number of times to print \"Yay!\": ");



            int oldYay = 0;


                var entry = Console.ReadLine();

                  try
                  {
                  var yay = int.Parse(entry);

                    if(yay < 0)
                    {
                      Console.WriteLine("You must enter a positive number.");
                      continue;
                    }





          while(true)
          {
              if(yay == oldYay)
                {
                    break;
                }
                else if(yay > oldYay)
                {
                    Console.WriteLine("Yay!");

                    oldYay += 1;
                }
            }
                  }
                  catch(System.FormatException)
                  {
                    Console.WriteLine("You must enter a whole number.");
                  }



            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
216,057 Points

:warning: Be careful about testing a challenge in the workspace.

If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.

In this case, you have an outer loop that prevents the program from ending. A program conforming to the challenge instructions will prompt and accept input only one time, and will output a number of "Yay!"s or an error message depending on the vapidity of the input, and then it will end.