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 trialLuis Santos
3,566 PointsI'm on the last task and I can't seem to get the validation sequence correct. Help will be really appreciated.
What am I missing here? I tried to define the negative number validation question the problem asks and nothing seems to work. I am really having a hard time with this last question.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
System.Console.WriteLine("Enter the number of times to print \"Yay!\": ");
var numOfTimes = System.Console.ReadLine();
try
{
int num = int.Parse(numOfTimes);
for (int i=0; i<num; i++) {
System.Console.WriteLine("\"Yay!\"");
}
}
catch (FormatException)
{
System.Console.WriteLine("You must enter a whole number.");
}
}
}
}
1 Answer
anil rahman
7,786 Pointsusing System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
System.Console.WriteLine("Enter the number of times to print \"Yay!\": ");
var numOfTimes = System.Console.ReadLine();
try
{
int num = int.Parse(numOfTimes);
if(num < 0)
{
System.Console.WriteLine("You must enter a positive number.");
}
for (int i=0; i<num; i++)
{
System.Console.WriteLine("\"Yay!\"");
}
}
catch (FormatException)
{
System.Console.WriteLine("You must enter a whole number.");
}
}
}
}