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 trialHianoo Song
6,812 PointsI can't find the reason why I'm getting "Bummer" sign on this
I tested this code on my workspace. and It did go well. I caught FormatException. and I got the number of "yay" I intended in ReadLine(). please help me (ㅠ_ㅠ)
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
int intNum = 0;
bool gotNumber = false;
while(!gotNumber){
try{
Console.Write("Enter the number of times to print \"Yay!\": ");
string stgNum = Console.ReadLine();
intNum = int.Parse(stgNum);
gotNumber = true;
}catch (FormatException){
Console.Write("You must enter a whole number.\n");
}catch (ArgumentNullException){
Console.Write("You must enter a whole number.\n");
}
}
int i=0;
while(i < intNum)
{
Console.Write("\"Yay\"");
i += 1;
}
}
}
}
2 Answers
Tarek El Hinaoui
Courses Plus Student 13,220 PointsHi Hiuwoo.. your code is working just fine
Tarek El Hinaoui
Courses Plus Student 13,220 PointsJust managed to repass the code challenge [SOLVED]
catch (Exception ex) when (ex is FormatException || ex is ArgumentNullException ){ Console.Write("You must enter a whole number.\n"); }
Tarek El Hinaoui
Courses Plus Student 13,220 PointsTarek El Hinaoui
Courses Plus Student 13,220 Pointsyou can get rid of catch (ArgumentNullException){ Console.Write("You must enter a whole number.\n"); }
Hianoo Song
6,812 PointsHianoo Song
6,812 PointsI also tried getting rid of argumentnullexception catch but Answer Checking Button wouldn't go next..