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 trialKristof Kocsis
15,455 PointsCode Challenge won't accept my code...
My code is fine in VS 2015 but the code challenge won't accept it...
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
//-----------------------------------
while (true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var i = 0;
try
{
var hanyszor = int.Parse(Console.ReadLine());
if (hanyszor <= 0)
{
Console.WriteLine("You must enter a number bigger than 0.");
continue;
}
while (i < hanyszor)
{
Console.WriteLine("Yay!");
i++;
}
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
break;
}
//-----------------------------------
Console.ReadKey();
}
}
}
2 Answers
Steven Parker
231,269 PointsYour program "works", but deviates from the instructions.
This is a great example of how something that works (will compile an run) might not be what was asked for (satisfies the requirements). This has been a topic of many previous questions, but I'll repost the info here:
People often over-think this one and get too creative, and their answer is rejected for a variety of reasons (some which don't seem to make any sense).
Here are the secret "rules" you must follow for success on this one:
- Your program must ask for and accept input ONE TIME ONLY
- If the input validates, your program will perform exactly as in Task 1
- If the input does not validate, it will print the error message and exit
- Validation must be done by exception catching. There are other perfectly good methods that can be used for validation, but they will not pass this challenge
It looks like you have a loop and extra input that both deviate from the first requirement.
Ernie Van Duyne
5,335 PointsTry to rememeber that the challenges are looking for one exact output to determine if the challenge is done properly. If you do extra that creates the proper outcome but with maybe a little extra it will not like the output.
Kristof Kocsis
15,455 PointsKristof Kocsis
15,455 PointsOk, it is just that in the previous videos if there was an error we always looped back to the beginning and so I taught I should do the same. I didn't realize that the app should exit after the error message.