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 trialJane Doe
447 PointsIm not sure what is wrong here. Help?
The final task is about not beeing able to write a negtive number. But my error is that it doesnt print out anything when a negativ number is written.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
try
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string input = Console.ReadLine();
int count = int.Parse(input);
int i = 0;
while(i < count)
{
if(count < 0)
{
Console.WriteLine("You must enter a positive number.");
continue;
}//if
else
{
i += 1;
Console.WriteLine("Yay!");
}//else
}//try
}//while
catch(FormatException)
{
Console.WriteLine("You must enter a whole number.");
}//catch
}
}
}
2 Answers
Steven Parker
231,248 PointsYou're really close. Just check the entered value before you begin the loop.
Jane Doe
447 PointsAh, I see! Ty Steven!
Steven Parker
231,248 PointsJane Doe — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!