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

How do I type a string as many times as the users number?

I need help with this challenge

Program.cs
using System;

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

        }
    }
}

3 Answers

Pablo Rocha
Pablo Rocha
10,142 Points

I won't give you the exact answer, but what you are supposed to do is use a for loop.

Take the number the user inputs and use it to loop that many times. During each loop print yay!

for (int i = 0; i < userInput; i++)
{
   // Print out yay!
}

ok thanks!

Steven Parker
Steven Parker
231,108 Points

:point_right: There's a few steps to this:

  • Input the user's response.
  • Convert the response to a number
  • Use the number as a loop counter
  • Inside the loop, print the message

You've done all these things in previous challenges, here you just put them all together.

how do I use a number as a loop counter?

You can read the number that is entered and assign it to a variable. Then use that variable to control a loop that prints "Yay!" to the console. You might want to rewatch the video if that sounds confusing, or ask a more specific question about the code you are trying to get to work.