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

Preston Ransbottom
Preston Ransbottom
3,359 Points

I keep getting a compile error with this.. However this compiles in my visual studio and runs in the console just fine..

Why will this not compile?

Program.cs
using System;

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


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

                if (entry.ToLower() == "quit")
                {
                    break;
                }


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

                    if (reps <= 0)
                    {
                        Console.WriteLine("You must enter a positive number.");
                        continue;
                    }

                    for (var i = 0; i < reps; i++)
                    {

                        Console.WriteLine("Yay!");
                    }

                }
                catch (FormatException)
                {

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

            }


        }
    }
}

2 Answers

Steven Parker
Steven Parker
229,744 Points

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

The challenge tester doesn't expect to have to enter "quit".

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.

Preston Ransbottom
Preston Ransbottom
3,359 Points

Hi Steve,

Thank for the reply. I have addressed and now it's compiling.

Thank