C# C# Basics Perfect Final

Joshua Thao
Joshua Thao
2,673 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
159,841 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.