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

Michael Bowen
Michael Bowen
788 Points

Why does this code work perfectly when I actually compile it, but not in the test editor?

The code is attached. It's strange, it compiles and works fine on my computer, but in the browser editor it just says "Bummer! Try again!" with no stack trace or message.

Program.cs
using System;
using System.IO;

namespace Treehouse.CodeChallenges {
  class Program {
    static void Main () {
      while (true) {
        Console.Write ("Enter the number of times to print \"Yay!\": ");
        var input = Console.ReadLine ();
        try {
          var times = int.Parse (input);

          if (times <= 0) {
            Console.WriteLine ("input must be greater than 0");
            continue;
          } else {
            var i = 0;

            while (i < times) {
              Console.WriteLine ("Yay!");
              i++;
            }
            break;
          }
        } catch (System.IO.IOException) {
          Console.WriteLine ("You must enter a whole number.");
          continue;
        } catch (FormatException) {
          Console.WriteLine ("You must enter a whole number.");
          continue;
        } catch (ArgumentNullException) {
          Console.WriteLine ("You must enter a whole number.");
          continue;
        }
      }
    }
  }
}

1 Answer

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Hi Michael,

The task didn't ask to wrap the logic in a while loop, so try removing the the first while loop (and related continue statements) to see if that fixes it.

Michael Bowen
Michael Bowen
788 Points

Thanks Chris, that fixed it!