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

Will Melton
Will Melton
7,096 Points

Am I missing something on question 2 of the Final?

I seem to get the program to work just fine in visual studio as I run my tests and it does everything that is asked. What am I missing to answer this properly then as it keeps saying it is not correct?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            bool keepGoing = true;
            int count = 0;


            while (keepGoing)
            {
                Console.Write("Enter the number of times to print \"Yay!\": ");

                string entry = Console.ReadLine();

                try
                {
                    int yayTimes = int.Parse(entry);

                    while (keepGoing)
                    {
                        Console.WriteLine("Yay!");
                        count = count + 1;
                        if (count == yayTimes)
                        {
                            keepGoing = false;
                        }
                    }
                }
                catch(FormatException)
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }

            }

        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,235 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 added an extra loop that prevents the program from ending.

A program that follows the challenge instructions will only ask for input one time, and either print "Yay!"s or an error message. But either way it should end.