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

Problem passing C# code challenge

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var repeat = int.parse(Console.ReadLine());
            var count = 0;
            var brake = false;
            While (brake == false){
                Console.WriteLine("Yay!");
                Count += 1;
            If (count == repeat){

            brake = true;
            }
            }


        }
    }
}

3 Answers

Paul Ryan
Paul Ryan
4,584 Points

From first glance, your count variable in the loop is uppercase. It should be lowercase.

Be careful with methods and ensure you are using the correct case. This will cause errors. Methods and variables are case sensitive.

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            int repeat = int.Parse(Console.ReadLine());
            while(repeat > 0){
              Console.WriteLine("Yay!");
              repeat--;
            }

        }
    }
}

that is how I would approach it. Any questions just ask me.

Also noticed you are using var. I wouldn't recommend using var unless you have a very good reason.

Brecht Philips
Brecht Philips
8,863 Points

Or you can use this while(count <= repeat){ Console.Writeline("Yay!"); count++; } Or a for loop for(int i=0; i < repeat ; i++){ Console.Writeline("Yay!"); }