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 trialMichael Bowen
788 PointsWhy 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.
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
Java Web Development Techdegree Graduate 23,933 PointsHi 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
788 PointsMichael Bowen
788 PointsThanks Chris, that fixed it!
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsNo problem!
Not to be a point-monger :), but do you mind marking my answer as the Accepted Answer if it solved your issue?
Thanks!