Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect Final

Mathias Nicolajsen
Mathias Nicolajsen
3,042 Points

Can anyone pls help me?

I don't understad why it dosen't work :( Pls help me!

Program.cs
using System;

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

            while (true)
            {
                try
                {
                    if (times <= 0)
                    {
                        Console.WriteLine("Yay!");
                    }
                    else
                    {
                        break;
                    }
                }
                catch(FormatException)
                {
                    Console.WriteLine("That is not a valid input.");
                    continue;
                }
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
216,136 Points

Make sure your program can end.

If the input is not valid, you should print out an error message and then end. And if it is valid, you need to keep a count of the times you go through the loop so you can end. If you don't modify your counter inside the loop, the test will always be true and the loop will never stop.