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

omer syed
omer syed
8,634 Points

Code not submitting

Hi!

I finished my code for the final project on C# Basics and its still showing an error. I ran the exact code in Visual Studio and tested the input validation in the console and it works fine. Just wondering if it can be checked out so that i can move on.

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 input = Console.ReadLine();
                    var howManyTimes = int.Parse(input);

                    if (howManyTimes < 0)
                    {
                        Console.WriteLine("You must enter a positive number.");
                        continue;
                    }
                    else
                    {
                        for (var i = 0; i <= howManyTimes - 1; i++)
                        {
                            Console.WriteLine("Yay!");
                        }
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

:warning: Be careful about testing a challenge in an external REPL or IDE.

If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.

In this case, you have an outer loop that prevents the program from ending. A program built according to the instructions will prompt and accept input one time, and based on the input it will either print "Yay!"s or an error mesage. Either way, it should end. With the extra loop it never ends.