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

Andrada Terenche
Andrada Terenche
1,103 Points

Bummer!Try again!

It doesn't show any errors, but it says "Bummer! Try again!" when I try to submit.

Program.cs
using System;

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

            try
            {
            var redo = int.Parse(input);

                    while (redo != 0) 
                        {
                                   Console.WriteLine("Yay!");
                                     redo -= 1;
                    }
            }
            catch (FormatException)
            {
                Console.WriteLine("You must enter a whole number.");
            }
            catch (OverflowException)
            {
                Console.WriteLine("You must enter a positive number.");
            }
        }
    }
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey there,

OverflowException doesn't catch negative numbers. Here's the Documentation.

To solve and prevent a negative entry, you need to use an if statement inside of the try block.

Give it another go with that in mind.

If you're still stuck, you can have a look at other posts in the Community for this challenge.

:dizzy: