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

Jason Rice
Jason Rice
6,657 Points

I keep getting a NullReference exception. works just fine in visual studio.

I've entered this code into C# Visual Studio, works just fine. I keep getting NullReference exception. I've blow through everything so far, this last exercise has me completely stumped. Very annoying.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {

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

                var numberOfRepeats = int.Parse(entry);
                var n = 0;

                while (n < numberOfRepeats)
                {
                    Console.WriteLine("\"Yay!\"");
                    n++;
                }
                Console.ReadLine();
            }
        }
    }
}

2 Answers

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 Points

Hi Jason,

You have some extra unneeded code that is blocking you.

1) Remove the outer while loop. It is an infinite loop and is not required.

2) Remove the if statement testing if to quit. Since you have removed the outer loop, then this is not needed.

I deleted these from your code and it passed the first part of the challenge.

Jason Rice
Jason Rice
6,657 Points

Thank you for your help. I honestly didn't think I would get a response, haha.

You're right, that worked for me. Thanks again!