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 final code should be right, right?

The final ask for a prompt inout from the user to print "Yay!" as many times as it says to print it. I'm pretty sure my code is right but it says it can't run it. Can anyone help?

using System;

namespace Treehouse.CodeChallenges { class Program { static void Main() { Console.Write("Enter the number of times to print \"Yay!\": "); int yay = 0; string yay2 = "Yay!";

        while(true)
        {
            if(yay != 0)
            {
                Console.WriteLine(yay2);
                yay -=1;
            }
            else
            {
                break;
            }
        }
    }
}

}

This is my code so far.

1 Answer

Matt Nicholas
Matt Nicholas
9,068 Points

Hey Patrick, It looks like maybe you are missing a closing bracket? Aside from that your code should work. You could clean it up a bit by just using the value of yay as your while loop boolean.

while(yay > 0){
    Console.WriteLine(yay2);
    yay --;
}