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

Maxim Antonenko
Maxim Antonenko
4,353 Points

Code works correctly on workplace, but there is an error in challenge task

C# Basics, Final step, Challenge Task 2 of 3.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
  class Program
  {
    static void Main()
    {
      while(true)
      {
        try
        {
          Console.Write("Enter the number of times to print \"Yay!\": ");
          string entry = Console.ReadLine();
          int counter = int.Parse(entry);
          while(counter > 0)
          {
            counter -= 1;
            Console.Write("Yay!");
          }
        }
        catch(FormatException)
        {
          Console.WriteLine("You must enter a whole number.");
          continue;
        }
        break;
      }
    }
  }
}

2 Answers

Steven Parker
Steven Parker
231,248 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 extra outer loop that prevents the program from ever finishing if it gets a bad input. The challenge expects it to output a number of "Yay!"s (or one error message) and then end.