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

C# Basics - Challenge Task 2 of 3 - What am I missing?

For some reason my code is not passing; however I can compile run on my local dev box. Could someone have a look and see what I might be missing please? (Code Attached)

Thanks in advance!

Program.cs
using System;

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

                    while (counter < printCount)
                    {
                        Console.WriteLine("Yay!");
                        counter += 1;
                    }
                    break;
                }
                catch (FormatException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }
                catch (ArgumentNullException)
                {
                    continue;
                }
            }
        }
    }
}

tried with for loop as well:

using System;

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

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

1 Answer

Thanks Steven!

Your program must ask for and accept input ONE TIME ONLY, s/continue/return/g

CaH