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 trialArchie Byard
774 PointsThe 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.
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
231,236 PointsBe 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.