Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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