Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Eugene Lee
11,890 Pointson C# for final coding on first segment that uses try and catch, i think i got right answer, but autograder is unhappy
on c#, i got to fix coding with try and catch as well as fixing while loop. i did everything i could to get to fix. but i am not getting right answer. i am trying to find out the issue
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{ try {
Console.Write("Enter the number of times to print \"Yay!\": ");
string input = Console.ReadLine();
int count = int.Parse(input);
int i = 0;
while(i < count)
{
i++;
count = i + 1;
Console.WriteLine("Yay!");
} } catch(FormatException) { Console.WriteLine("You must enter a whole number."); }
}
}
}
1 Answer

Steven Parker
216,121 PointsThe problem is due to a line you added to the inner loop of the provided code:
while(i < count)
{
i++;
count = i + 1; // why?
By setting "count" to one more than "i", then "i" will always be less than "count", which means the loop condition will always be true and the loop will run forever.
Without that line, the exception handling additions work as required and you'll pass task 1.
Eugene Lee
11,890 PointsEugene Lee
11,890 Pointsthank you so much