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

Can't figure out why my code won't pass test for task 2--no error information given.

It just says "Bummer! Try again!" Anyone have any ideas? Thanks!

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());

                 }


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

                }

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

                }

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

                }

                 if (howmanytimes >= 0)
                    {
                        goodinput = true;
                    }
                    else
                    {
                        Console.WriteLine("You must enter a whole number.");
                    }

            }


            while (numberoftimes < howmanytimes)
            {


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

        }
    }
}

1 Answer

Copy pasting a previous answer of mine:

Your code is technically functional, but the "continue;" in the catch block is throwing a compiler error. The "continue" keyword is used to skip the current iteration of a loop, and not to return to a different part of the program. Since a catch block is not a loop, it cannot skip an iteration of a loop and continue looping thereafter. Simply remove the "continue;" and your code should pass the challenge just fine.