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

Brad Rock
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brad Rock
Full Stack JavaScript Techdegree Graduate 20,769 Points

Stuck on Task 3 of the Final

Can't figure out why this won't pass...I tested it in the workspace and can't find a case that doesn't satisfy the requirements. No info on why it doesn't pass, just a message that says "Bummer! Try again!" Anyone have any ideas?

Program.cs
using System;

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

            int howmanytimes = 0;

            int numberoftimes = 0;

            bool goodinput = false;

            while(goodinput == false)
            {


                try 
                {
                    howmanytimes = int.Parse(Console.ReadLine());

                      if (howmanytimes < 0)
                        {

                        Console.WriteLine("You must enter a positive number.");

                        }

                    else
                    {
                        goodinput = true;
                    }


                 }


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


                }

                 catch (ArgumentException argex)
                {
                    Console.WriteLine("You must enter a whole number.");


                }

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


                }



            }


            while (numberoftimes < howmanytimes)
            {


             Console.WriteLine("Yay!");
             numberoftimes += 1;
            }

        }
    }
}

1 Answer

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.

Also, you only need to catch FormatException, the others are not necessary (but probably don't affect passing).