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

I cannot seem to figure this one out, I dont know If im missing something or not.

Should I have a while(true)? When I place continue inside the first if statement i get error CS0139. I dont get what I need to do, maybe the question is really confusing me.

Program.cs
using System;

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


            try {

            Console.Write("Enter the number of times to print \"Yay!\": ");
            string input = Console.ReadLine();

            int count = int.Parse(input);
         if(count < 0)
         {

         }

          else {
            int i = 0;
            while(i < count)
            {
                i += 1;   
                Console.WriteLine("Yay!");
            }
        }
            }
        catch(FormatException)
        {
              Console.WriteLine("You must enter a positive number.");

        }

      }
    }
}

1 Answer

Steven Parker
Steven Parker
218,679 Points

Are you working on task 1 or 2? If it's task 1, you've got the wrong error message: The challenge says, " Bummer! I entered 2.5. I expected "You must enter a whole number.", but got "You must enter a positive number." instead."

If you're working on task 2, the task 1 code should still be there to check for non-whole numbers, but you'll need to add some more code to check if the number entered is positive or not and then show a different error message (the one you have above) if not. Right now, the challenge says, "Bummer! I entered -1, but nothing was printed out"