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

nave lahav
nave lahav
388 Points

why is this false?

it seems to run fine but doesnt complete the challenge

Program.cs
using System;

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

                int  i = 0;
                while(i != number)
                {
                    if(number<=0){
                    Console.Write("You must enter a positive number.");
                    continue;}
                    i+=1;
                    Console.WriteLine("Yay");

                }

             }
            catch(FormatException)
            {
                Console.Write("You must enter a whole number.");

            }






        }
    }
}

1 Answer

Jon Wood
Jon Wood
9,884 Points

You almost got it! I believe your negative number check just needs to be moved before the while loop. Try moving that and, since you're not in a loop anymore you can remove the continue statement. Also, try to make it so that if the input is a negative number it doesn't go into the while loop and just prints to the console. Let me know if you need more help!

nave lahav
nave lahav
388 Points

I did exactly what you said and I have the same problem, btw thanks for replying its relly helpful

Jon Wood
Jon Wood
9,884 Points

nave lahav Can you post your new code? I'll take a look at that to help you a bit further. :)