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

help please

using System;

namespace Treehouse.CodeChallenges { class Program { static void Main() { int number = 0;

    {
        Console.Write("Enter the number of times to print \"Yay!\": ");
        Console.ReadLine (number);

        if (number > 0)
        {
        for (int x = 1, x < number, x++)
            x = ("Yay!");
            {
            Console.WriteLine(x);
            }
        }
    }
    }
}

}

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            int number = 0;

        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            Console.ReadLine (number);

            if (number > 0)
            {
            for (int x = 1, x < number, x++)
                x = ("Yay!");
                {
                Console.WriteLine(x);
                }
            }
        }
        }
    }
}

1 Answer

Chanuka Weerasinghe
Chanuka Weerasinghe
2,337 Points

You need to convert the number to integer.

var num = int.Parse(number)

then use this num variable for the iterations.

Example code : No more, No less. I mean really! Nothing else. Place this in your Main class and run, Then make sure to study the video again to get better understanding.

        Console.Write("Enter the number of times to print \"Yay!\": ");
        var numOfTimes = System.Console.ReadLine();
        int num = int.Parse(numOfTimes);
        for (int i = 0; i < num; i++)
        {
            Console.WriteLine("\"Yay!\"");
        }