Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect Final

Bummer! Try again!

I'm just getting the Bummer! Try again! and i can not figure out what is wrong with my code.

Program.cs
using System;

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


            while(true)
            {
                Console.WriteLine("Enter the number of times to print \"Yay!\": ");
                string entered = Console.ReadLine();
            //  Console.WriteLine("You entered: " + entered);

                try
                {
                    if (entered == null) {
                        continue;
                    }
                    double countingTo = int.Parse(entered);
                    if(countingTo < 1 )
                    {
                        Console.WriteLine("You must enter a whole number.");
                        continue;
                    }
                    for(int i = 0;i < countingTo;i++)
                    {
                        Console.WriteLine("Yay!");
                    }
                    break;

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


        }

    }

}

1 Answer

Steven Parker
Steven Parker
216,057 Points

Your program works differently from the instructions.

In this case, you have added 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.

Thank you for the help, i finished the challenge after removing the extra loop!