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

Works in VS, all I am getting is "Bummer! Try again!

Initially it was failing due to an ArgumentNullException, so I added a catch for that and now I am not getting any output on the preview tab and it is not telling me why it is failing.

I copied it to VS 2015 and it works just fine. I have not found a way to input a null value though.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
          while (true)
            {
                try
                {
                    Console.Write("Enter the number of times to print \"Yay!\": ");
                    var times = int.Parse(Console.ReadLine());

                    for (int i = 0; i < times; i++)
                    {
                        Console.WriteLine("Yay!");
                    }
                    break;
                }
                catch (FormatException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }
                catch (ArgumentNullException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }
            }
        }
    }
}

2 Answers

Change the continues in your catches to breaks. For some reason it doesn't want you to actually loop back to the original question "Enter the number of times to print "Yay!":"

Paul Ryan
Paul Ryan
4,584 Points

I might be wrong but I think it might be cause by your continue statement in the catch blocks.

Due to them the last line on the console when the user ends a incorrect value will be: Console.Write("Enter the number of times to print \"Yay!\": ");

Maybe try remove the continue statements from the catch blocks and see does that solve your issue.