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 trial

C# C# Basics (Retired) Perfect Final

Fails 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

Program.cs
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;
                }
            }


        }
    }
}
K Cleveland
K Cleveland
21,839 Points

How does this work in Visual Studio? You built this and it compiled and then you were able to run without errors? Thanks!

Hi 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
Steven Parker
229,732 Points

Any 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.

Hi 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
Steven Parker
229,732 Points

There will always be ways to make a program better, but the challenges are are looking for specific functionality based on the instructions.