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

Joshua Thao
Joshua Thao
6,438 Points

Bummer error about the prompt

What is going on here? The output works in Visual studio just fine. Please help

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            int count = -1;
            while(count < 0)
            {
                try
                {
                    Console.WriteLine("Enter the number of times to print \"Yay!\"");
                    string input = Console.ReadLine();
                    count = int.Parse(input);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: The input was not a whole number.");
                }

                if(count < 0)
                Console.WriteLine("You must enter a positive number.");
                }

                while (count > 0)
                {
                    count--;
                    Console.WriteLine("Yay!");
                }       
        }
    }
}

1 Answer

Steven Parker
Steven Parker
215,984 Points

The challenge has specific expectations beyond just being able to compile and run (like in VS).

This program should have only one loop, and whether the input is good or not a program constructed according to the instructions should end. But the code here has an extra loop that would cause it to ask for input a second time after an error.