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

Ryan Behnke
Ryan Behnke
2,839 Points

Your compiler gives no feedback on this

using System;

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

        while (true)
        {

                try
                {
                     var trys = Int32.Parse(entry);

                    if (count == trys && trys != 0)
                     {
                        break;
                     }
                    else if(trys <= 0)
                     {
                        Console.WriteLine("You must enter a whole number.");
                        continue;
                     }
                     else if(count < trys)
                     {
                         Console.WriteLine("Yay!"); 
                     }
                     else 
                     {
                        Console.WriteLine("Yay!");     
                     }
                    count += 1;

                }
               catch(FormatException)
               {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
               }
        }
    }
}

}

Program.cs
using System;

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


            while (true)
            {

                    try
                    {
                         var trys = Int32.Parse(entry);

                        if (count == trys && trys != 0)
                         {
                            break;
                         }
                        else if(trys <= 0)
                         {
                            Console.WriteLine("You must enter a whole number.");
                            continue;
                         }
                         else if(count < trys)
                         {
                             Console.WriteLine("Yay!"); 
                         }
                         else 
                         {
                            Console.WriteLine("Yay!");     
                         }
                        count += 1;

                    }
                   catch(FormatException)
                   {
                        Console.WriteLine("You must enter a whole number.");
                        continue;
                   }
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,210 Points

The challenge is checking for correct operation, so error-free compilation isn't enough to pass the challenge.

In this case, you have structured your loop in a way 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 message. Either way, it should end.