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 trialMaddison Manente
555 PointsWhy doesn't my code for Challenge task 2 of 3 in the C# Basics Final work?
I have tested my code in Workspaces and it does what the question asks but when I check my answer it says "bummer, try again" and gives me no explanation for why. Can somebody help?
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
bool repeat = true;
while (repeat)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string entry = Console.ReadLine();
try
{
int numYay = int.Parse(entry);
bool keepGoing = true;
int total = 0;
while (keepGoing)
{
Console.WriteLine("Yay");
total = total + 1;
if (total == numYay)
{
keepGoing = false;
repeat = false;
}
else
{
continue;
}
}
}
catch(FormatException)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
}
}
}
}
1 Answer
James King
5,529 PointsYou're missing a parameter in the catch block. Try adding the below code:
catch (FormatException e) { Console.WriteLine("You must enter a whole number."); continue; }
It still runs fine, just my guess as to what the task is looking for.
James King
5,529 PointsJames King
5,529 PointsI actually just copied and pasted you're code in the challenge and it worked fine, maybe try refreshing your browser?
Maddison Manente
555 PointsMaddison Manente
555 PointsThank you for helping me out! I tried adding the parameter in the catch block and I refreshed my browser but neither one worked.