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

i dont know what i must write

i write a code but what a problem

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            try
            {
                var enter =int.Parse(Console.ReadLine());
                var com=1;
                while(true)
                    {
                    Console.Write("Yay!"+ enter);
                    if(com == enter )
                        {
                             break;
                        }
                    com +=1;
                }
            }
            catch(FormatException)
            {
                Console.WriteLine("You must enter a whole number");

            }

        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,096 Points

You might need to make your loop work differently.

Think about what your program would do if the user asked for 0 outputs. You might want to check if any more are needed before you write each one. The loop itself gives you a handy way to make a test before each iteration if you put a test expression in the parentheses after the while (instead of "true").

And the challenge didn't ask for the outputs to be numbered. You might want to avoid doing anything not asked for to prevent confusing the checking system.

Also, these challenges tend to be very picky about output strings, and it looks like you left off the period at the end of the error message.