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

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
228,991 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"