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 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 --;
}