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

Final C# basics challenge.

Please could someone tell me where I have gone wrong in the code. The error message says something about string and Null and I don't know what that means.

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();

                     try
                {
                    var reps = Int32.Parse(entry);
                    if (reps <= 0)
                    {
                        Console.WriteLine("You must enter a positive number.");
                        continue;
                    }

                    for (var i = 0; i < reps; i++)
                    {

                        Console.WriteLine("Yay!");
                    }

                }
                catch (FormatException)
                {

                    Console.WriteLine("You must enter a whole number.");
                    continue;
                }

        }
        }




    }
}

1 Answer

Steven Parker
Steven Parker
229,608 Points

You have an outer loop that prevents the program from ending.

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.