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

I am getting an error that task 1 is no longer working, but when I go back to task 1, i dont make any changes, it works.

I am getting an error that task 1 is no longer working, but when I go back to task 1, i dont make any changes, it works. What is happening?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {


            while(true)
            {
                Console.Write("Enter the number of times to print \"Yay!\": ");

                // get user's input for times to say 'Yay'
                string entry = Console.ReadLine();

                try
                {
                    // convert string entry to int
                    var output = int.Parse(entry);
                    // print to screen the times the user specifies

                    for(int i = 0; i < output; i++)
                    {
                        Console.Write("Yay!\n");
                    }
                }
              /*  catch(NullReferenceException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }*/
                catch(FormatException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }
            }



        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,248 Points

You have an outer loop that prevents the program from ending.

A program built according to the instructions will prompt and accept input one time, and based on the input it will either print "Yay!"s or an error mesage. Either way, it should end. With the extra loop it never ends.

Since task 1 has no error conditions, the tester might not check that the program ends or try running it more than once.

Robert Silva
Robert Silva
6,450 Points
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var input = Console.ReadLine();


            try
            {
                int test = int.Parse(input);

               for(int i = 0; i < test; i++)
                {
                    Console.WriteLine("Yay!");
                }

                if(test <= 0)
                {
                    Console.WriteLine("You must enter a positive number.");
                }
            }
            catch(FormatException)
            {
                Console.WriteLine("You must enter a whole number.");
            }


        }
    }
}
Steven Parker
Steven Parker
231,248 Points

You might be jumping ahead here, I think Joel might still be on task 2. Also, Treehouse discourages posting of explicit solutions with no explanation.