A X

A X

  • NA
  • 18
  • 8.9k

Just need some help with a simple code, maybe not so simple.

Sep 4 2013 2:33 AM
I almost got it but im having trouble with the finishing touch. i want to create a method that subtracts 3 from 3 numbers inputted by the user and show them at the end of the program. it tells me that x is unassigned but when i declare it inside the method it tells me there is a 'parent' use of the variable, whats going wrong here.......any help or tips would be soo appreciated. thank you in advance.

Here is what I have so far.......

    class Program
    {


        static void Main(string[] args)
        {
            int x;
            int []a = new int[3];

            for (x = 0; x < 3; x++)
            {
                Console.Write("enter number = "+  x);
                a[x] = Int32.Parse(Console.ReadLine());
            }

            method(a);


        }
        static void method(int[] a)
        {
          
            for (int x = x - 3; x < 3; x++) //****my problem is here...where i put "int x = x - 3"                                                     // the program tells me that "use of unassigned local                                                     // variable x" what does that mean? when i try to                                                    //  declare it inside the method it gives me
                                                  //    more errors, why? and how do i fix it?
            {
                Console.Writeline("first number subtracted by 3 ~~> " + x);
            }
        }
    }
}

Answers (4)