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

Rahul Gupta
Rahul Gupta
667 Points

Code Challenge Error .

I am confused as to why this is not working. The code challenge 2 says that if the user enters any numbers in decimals, the output should be "Please enter a whole number " which worked and then i moved on to Challenge 3 where it wanted me the code to output "Please enter positive number " if the user enters a negative number like -1 or something . I coded on VS and it works fine with all the different situations but when i click on check work it says that "It looks like task two is no longer working " . The code is the same and it works on VS . Any suggestions ?

Thanks in advance

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");

            try
            {
                int Number = int.Parse(Console.ReadLine());
                if (Number<0 )
                {
                    Console.WriteLine("You must enter a positive number.");
                }

                while (Number > 0)
                {
                    Console.WriteLine("Yay");
                    Number--;
                }

            }
            catch (FormatException)
            {
                Console.WriteLine("Please enter a whole number ");

            }

        }
    }
}

2 Answers

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

Hi Rahul,

I just was able to successfully complete the challenge with your code, but I got a feedback on stage 2 that told me that the warning should be "You must enter a whole number.", rather than "Please enter a whole number."

After correcting this, I was able to complete all 3 tasks in the challenge.

Hope that helps,

Regards,

Nathan W

Rahul Gupta
Rahul Gupta
667 Points

Thanks Nathan , That was really silly of me . I have been working on Visual Studio and had a different wording there :)