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

Sergey Odintsov
Sergey Odintsov
1,071 Points

Challenge checker doesn't except my code, yet it works in console

Tester says "Bummer! System.ArgumentNullException: Value cannot be null. Parameter name: String. See output for stack trace."

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            var numberWritten = 0;

            while (true)
            {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var entry = Console.ReadLine();

                try 
                {
                var repeat = int.Parse (entry);

                    while (true)
                    {
                        if (numberWritten < repeat)
                        {
                              Console.WriteLine("Yay!");
                              numberWritten += 1;

                        }

                        else
                        {
                            break;
                        }

                    } 

                }

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




        }
    }
}        
Sergey Odintsov
Sergey Odintsov
1,071 Points

System.ArgumentNullException: Value cannot be null. Parameter name: String at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00054] in /builddir/build/BUILD/mono-4.8.0/mcs/class/referencesource/mscorlib/system/number.cs:1074 at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /builddir/build/BUILD/mono-4.8.0/mcs/class/referencesource/mscorlib/system/number.cs:745 at System.Int32.Parse (System.String s) [0x00000] in /builddir/build/BUILD/mono-4.8.0/mcs/class/referencesource/mscorlib/system/int32.cs:120 at Treehouse.CodeChallenges.Program.Main () [0x00012] in :0 at MonoTester.Run () [0x00197] in MonoTester.cs:125 at MonoTester.Main (System.String[] args) [0x00013] in MonoTester.cs:28

1 Answer

Steven Parker
Steven Parker
231,248 Points

:warning: Be careful about testing a challenge in an external REPL.

If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.

In this case, you have added an extra loop that prevents the program from ending if bad values are entered..

A program that follows the challenge instructions will only ask for input one time, and either print "Yay!"s or an error message. But either way it should end.

Sergey Odintsov
Sergey Odintsov
1,071 Points

Thanks! I guess I have overdone the challenge a bit :)