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

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. :)