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 trialPhilip Collins
13,249 Pointsthe final challenge
Why isn't my code running?
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
while(true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string entry = Console.ReadLine();
if ( entry.ToLower = "quit")
{
break;
}
try
{
int printTimes = int.Parse(entry);
int count = 0;
if(printTimes < 0 )
{
Console.WriteLine("This is an invalid input.");
continue;
}
while(printTimes != count)
{
Console.WriteLine("Yay!");
count += 1;
continue;
}
}
catch(FormatException)
{
Console.WriteLine("Invalid Input, Please input a whole number.");
continue;
}
}
}
}
}
1 Answer
Simon Coates
28,694 Pointsit accepts:
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
string value = Console.ReadLine();
try {
int printTimes = int.Parse(value);
if(printTimes<0)
{
Console.WriteLine("You must enter a positive number.");
} else {
for(int i = 0; i < printTimes; i++)
{
Console.WriteLine("Yay!");
}
}
} catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
}
}
}
}
Simon Coates
28,694 PointsSimon Coates
28,694 Pointswith if ( entry.ToLower = "quit") , the = is assignment rather than an equality test (==). Plus ToLower is a method call, requiring (). There's still stuff wrong. I'll check it out and hopefully give you a full answer.