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

Dejan Strancar
Dejan Strancar
12,382 Points

This code is passing in a separate wokspace

putting the code from step 3 in a separate wokspace, compiling and running it works just as intended and specified by the task. What am i missing here?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {

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


                try{
                   var entry = Console.ReadLine();

                        int count = Int32.Parse(entry);
                        if (Int32.TryParse(entry, out count)){
                            if (count <= 0){
                                Console.WriteLine("You must enter a positive number.");
                                continue;
                            }
                            while (  count > 0){
                                Console.WriteLine("Yay!");
                                count--;
                            }

                        }else{
                            continue;
                        }


                    }
                 catch(FormatException){
                    Console.WriteLine("You must enter a whole number.");
                   continue;
                }
                 break;
            } 


        }
    }
}

1 Answer

Steven Parker
Steven Parker
215,954 Points

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

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

In this case, it looks like you have an outer loop that will prevent the program from ending after it outputs an error message. According to the challenge instructions, the program should output "Yay!"s on a valid input, and output an error message on an invalid input, and either way it should end.