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

Mytch Hagan
Mytch Hagan
1,876 Points

I'm having a bit of trouble with the final steps.

I can't figure out what's wrong.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var input = Console.ReadLine();

            try {
                var counter = Convert.ToInt32(input);
                var count = 0;

                while (count < counter)
                {
                    if (counter <= 0) {
                     Console.WriteLine("You must enter a positive number.");   
                    }
                    Console.WriteLine("\"Yay!\"");
                    count++;

                }
            }
            catch (FormatException)  {
                Console.WriteLine("You must enter a whole number.");
            }
        }
    }
}
Mytch Hagan
Mytch Hagan
1,876 Points

Never mind, I found the answer to the question.

1 Answer

Steven Parker
Steven Parker
231,269 Points

You should test for invalid (not positive) input before the loop.

If the input is not valid the program should print the error message and then exit. The error message should be shown only one time and no "Yay!"s should be printed.