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# Basic Final (beginner): Stuck on while, if, and else if.The program does return to the command prompt after running.

Hello, I am working on the C# beginner's code challenge. The task is to print the string "Yay!" for the # entered by the user. The first of the code works. The program prints Yay for the number entered. The challenge is getting my else statement to work in the case that a negative number is entered. When a negative number is entered the program jumps back to the command prompt. Here's the piece of code:

int numberValue = 1; 
             int numberYay = int.Parse(numberEntry);

              while(numberValue <= numberYay)

                if (numberYay >= 1)

                  numberValue += 1;
                         Console.WriteLine("Please enter a positive number.");


          catch (FormatException)
                    Console.WriteLine("That is not an acceptable entry! Please enter a whole number.");

Thanks for taking the time to look at this.

Thank you for taking the time to look at this...

2 Answers

You should take another look at the while loop condition. Good luck!

Thank you!! I added another if statement outside of the while loop and got the result that I needed. It's a little confusing right now but I'll get it.