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 trialMytch Hagan
1,876 PointsI'm having a bit of trouble with the final steps.
I can't figure out what's wrong.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var input = Console.ReadLine();
try {
var counter = Convert.ToInt32(input);
var count = 0;
while (count < counter)
{
if (counter <= 0) {
Console.WriteLine("You must enter a positive number.");
}
Console.WriteLine("\"Yay!\"");
count++;
}
}
catch (FormatException) {
Console.WriteLine("You must enter a whole number.");
}
}
}
}
Steven Parker
231,269 PointsCongratulations!
1 Answer
Steven Parker
231,269 PointsYou should test for invalid (not positive) input before the loop.
If the input is not valid the program should print the error message and then exit. The error message should be shown only one time and no "Yay!"s should be printed.
Mytch Hagan
1,876 PointsMytch Hagan
1,876 PointsNever mind, I found the answer to the question.