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

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
230,274 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.