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

Not sure what i am doing wrong.

This final code challenge will require you to use almost everything we've covered in this course. You’ll write a program to celebrate completing this course by printing “Yay!” to the screen a given number of times.

Write a program that:

Prompts the user to enter the number of times to enter “Yay!”. I've done this for you. Leave this as it is.
Prints “Yay!” to the screen that number of times (Hint: You’ll need a loop for this. You’ll also need to keep track of how many times the loop has run).

You can print them all on the same line or on separate lines.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            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<input;i++)
           {
            Console.WriteLine("\"Yay!\"");

3 Answers

Chanuka Weerasinghe
Chanuka Weerasinghe
2,337 Points

I will list the changes so you will understand the reasons by yourself - Its a better way of learning.

1) Change - Readline to ReadLine - Capital "L";

2) In the for loop - for (int i = 0; i < num; i++) - You are iterating the loop using the number of times you specified.

I ran your code with these changes and it works!

Hi Margaret,

You're pretty close but there's a few issues.

Readline() should have a capital 'L'

In your for statement you have i<input but input isn't defined anywhere. You should use the variable num instead since that's what's storing how many times.

Also, make sure you have the proper amount of closing curly braces. Your code isn't showing the closing ones.

Thanks