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

jon emas
jon emas
2,056 Points

Can you double check and make sure my answer is actually incorrect?

I built the code submitted for question 2 on the c# final in Visual Studio. I have no problem running it to specifications from Visual Studio, but when I enter the exact source code into the answer field on TreeHouse it says my answer is incorrect.

Please help! Jon

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            //creating container while loop
            while(true)
            {
                //prompting and storing user input
                Console.Write("Enter the number of times to print \"Yay!\": ");
                string howMany = Console.ReadLine();

                //try to continue with user entry
                try
                {
                    //converting user input to integer
                    int entry = int.Parse(howMany);

                    if (entry < 0)
                    {
                        Console.WriteLine("Must enter positive number.");
                        continue;
                    }

                    //setting count to 0
                    int count = 1;

                    //while loop running until count is <= user input
                    while (count <= entry)
                    {
                        //writing "yay"
                        Console.WriteLine("Yay!");

                        //added 1 to count
                        count += 1;
                    }
                    break;
                }
                catch
                {
                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }
            }

        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

Remember that the challenge isn't just about making something that compiles and runs — it's about meeting certain performance requirements (and not doing things which were not asked for!).

I can tell you for certain that 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.

A program that asks for input repeatedly will not pass the challenge.