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 trialAlbertas Papendik
962 PointsFails first task requirement on second task, code remains unchanged. Works on Visual Studio - Fine
Code passes the first task, but fails on the second one stating its not passing the requirement of first task anymore. Although code remains unchanged
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
int i = 0;
bool carryOn = true;
while (carryOn == true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
String entry = Console.ReadLine();
try
{
int minutes = int.Parse(entry);
if (minutes <= 0)
{
Console.WriteLine("Enter valid number");
continue;
}
while (i < minutes)
{
Console.WriteLine("\"Yay!\"");
i = i + 1;
// carryOn = false;
}
break;
}
catch (FormatException)
{
Console.WriteLine("\"You must enter a whole number.\"");
continue;
}
}
}
}
}
Albertas Papendik
962 PointsHi K Cleveland, thanks for responding. it works as intended. Code is accepting any integer value and repeats "Yay!" as per input. In all other cases it throws exception "You must enter a whole number." Hope this helps
1 Answer
Steven Parker
231,210 PointsAny code that introduces an error can cause the re-validation of previous tasks to also fail.
But the issue in this case is an extra loop that prevents the program from ending if bad values are entered..
A program that follows the challenge instructions will only ask for input one time, and either print "Yay!"s or an error message. But either way it should end.
Albertas Papendik
962 PointsHi Stephen Parker,
Thank you for your reply. Changing continue to break in exception did fix the issue. Although program was more user friendly giving a chance for correct impute.
Your reply is correct.
Steven Parker
231,210 PointsThere will always be ways to make a program better, but the challenges are are looking for specific functionality based on the instructions.
K Cleveland
21,839 PointsK Cleveland
21,839 PointsHow does this work in Visual Studio? You built this and it compiled and then you were able to run without errors? Thanks!