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

Josh Boersma
PLUS
Josh Boersma
Courses Plus Student 2,486 Points

Code Refuses to Compile

I have checked over this code a hundred times and there are no logical discrepancies. I find no reason this shouldn't work, so hopefully a fresh pair of eyes can catch what I've missed. The worst part is I'm a CompSci major learning ASP.Net so this should be cake. I receive the error System.ArgumentNullException: Value cannot be null. Parameter name: String. See output for stack trace.

My code compiled and ran to completion fine in repl.it, so I'm not sure what error Treehouse is getting.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
           while (true){
               try{ 
                    Console.WriteLine("Enter the number of times to print \"Yay!\": ");
                    var c = Console.ReadLine();
                    int count = int.Parse(c);
                    if(count <= 0)
                    {
                        Console.WriteLine(c + " is not an acceptable value.");
                        continue;
                    }
                    int total = 0;
                    while (total < count)
                    {
                        Console.WriteLine("Yay!");
                        total = total + 1;
                    }
                    break;
                }   //try
                catch(FormatException)
                {
                    Console.WriteLine("That is not valid input.");
                    continue;
                }//catch
            }//while
        }  //Main
    }//class
}//namespaces

2 Answers

András Mezey
András Mezey
4,610 Points

Hello!

It's the second line the causing the problem. Remove the 'using Math;' and it will compile fine. Math is a class and not a namespace.

Cheers, Andrew

Josh Boersma
Josh Boersma
Courses Plus Student 2,486 Points

I noticed that earlier but forgot to update the code in the question, sorry. I receive the error

System.ArgumentNullException: Value cannot be null. Parameter name: String. See output for stack trace.

I ran my code in repl.it and it ran and completed fine, which confuses me even more.