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

Jeremy Poppe
Jeremy Poppe
3,677 Points

I'm struggling with dealing with local variables within loops. This has been an issue for me before this final challeng

I'm struggling to understand how to define the variable within the correct scope. Thank you.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            double entry;
            Console.Write("Enter the number of times to print \"Yay!\": ");
            entry = Convert.ToInt16(Console.ReadLine());
            while(entry => count)
            {

                Console.Write("yay!");
                int count = count + 1;  
            }


        }
    }
}

1 Answer

First thing I noticed is that you need to change => to >= in your comparison. After that, it looks like you need to declare count outside of your while loop. Leaving it inside the while loop keeps the scope within the loop and the count that is being compared to entry is never incremented.