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

Luka Cabarkapa
Luka Cabarkapa
1,022 Points

Can someone give me tips what have I missing here ? Thanks.

I got error saying that cant use a variable "unos"

Program.cs
using System;

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

              while(i<br)
            {
              var  unos=0;
                Console.WriteLine("You must enter a whole number."); 
            while(true)
            {
            try
            {
              var  s=Console.ReadLine();
                int unos=int.Parse(s);

            }
            catch(FormatException)
            {
            Console.WriteLine("this is not a valid input");
                continue;
            }
            }
                  Console.WriteLine("Yay!");
                i++;
            }



        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,096 Points

You're declaring that variable more than once.

The compiler is talking about line 22 where you have:

                int unos=int.Parse(s);

But there is a previous declaration on line 15:

              var  unos=0;

And it also looks like you have too many loops — make sure your program can end. A program that follows the challenge instructions will only ask for input one time, and either print "Yay!"s or an error message. But either way it should end.