
Maddison 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,410 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,410 PointsJames King
5,410 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.