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

Joshua Thao
Joshua Thao
6,439 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
231,275 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.