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

Final Challenge C#

Hey guys and girls, I am having trouble with the Final challenge task 1. Can someone tell me what is wrong in my code?

Thanks.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {

            int entry = Console.Write("Enter the number of times to print \"Yay!\": ");;
            while (entry == 5) {
            Console.WriteLine("Yay!" + " Yay!" + " Yay!" + " Yay!" + " Yay!");

            }

        }
    }
}

1 Answer

Jon Wood
Jon Wood
9,884 Points

You are only handling the scenario when entry is 5. You need to be able to handle different entries a user may input. If you're comfortable with it, I would suggest using a for loop that iterates depending on how many times the user input. Let me know if you need more help!

Hey Jon, I understand what you are saying. However, I just have a really hard time writing the code down for that matter, even though I know i need to use a loop that iterates depending on the entry of the user. Could you please give me some more help?

Thanks, GamingWithHan

Jon Wood
Jon Wood
9,884 Points

Of course! I reviewed the challenge and all you need to do is print out "Yay!" the number of times a user inputs. Check out this shell of code:

var entry = Console.ReadLine();
var numTimes = 0;

int.TryParse(entry, out numTimes);

for(int i = 0; i < ; i++)
{

}

I left the body of the for loop blank and the i < blank so you can give it a shot. I do use TryParse instead of Parse to help handle invalid inputs but I don't think it's required in this challenge. Hope it helps, but let me know if you need more.

Thanks so much!

Jon Wood
Jon Wood
9,884 Points

Anytime! Glad it helped! :)