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 trialRobert Merrill
1,064 PointsStuck on Yay!
I'm not quite sure what the code is actually error'ing out at. Something about Null. I added code to cover a zero (0) or less, NULL (At least I think that I did), and non-number input.
I think that I am close.
Thanks,
Rob
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
while (true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var times = Console.ReadLine();
try
{
var totalTimes = int.Parse(times);
if (totalTimes <= 0)
{
Console.WriteLine(totalTimes + " is not an acceptable value.");
continue;
}
while (totalTimes > 0)
{
Console.WriteLine("\"Yay!\" ");
totalTimes --;
}
}
catch(FormatException)
{
Console.WriteLine("That is not valid input.");
continue;
}
}
}
}
}
2 Answers
Steven Parker
231,248 PointsYou have an outer loop that prevents the program from ending.
A program built according to the instructions will prompt and accept input one time, and based on the input it will either print "Yay!"s or an error mesage. Either way, it should end. With the extra loop it never ends.
Also, zero might need to be allowed as a value (in which case the program would just end).
Robert Merrill
1,064 PointsThanks Steven!
I am moving on!!!
Rob
Robert Merrill
1,064 PointsRobert Merrill
1,064 PointsGotcha!
DONE!
Rob