jeudi 14 novembre 2019

C# Issues with if-statement and 2 arrays

The code runs up until the if statement in the second for-loop. Ive tried changing quite a lot of stuff -- added a second array so it doesn't conflict with the if statement. Debugged it and also changed the true statements of the last if but it never really passes through the 23 row and it shows System.IndexOutOfRangeException: Index was outside the bounds of the array.

            Console.WriteLine("Number of inputs: ");
            int numInput = int.Parse(Console.ReadLine());
            int[] arrayOfNumbers = new int[numInput];
            int[] arrayOfNumbersClone = new int[numInput];
            for (int inc = 0; inc < arrayOfNumbers.Length; inc++)
            {
                Console.Write("Enter {0} element: ", inc + 1);
                arrayOfNumbers[inc] = Int32.Parse(Console.ReadLine());
                arrayOfNumbersClone[inc] = arrayOfNumbers[inc];
            }
            for (int inc = 0, dec = numInput; inc2 < dec; inc2++, dec--)
            {
                if (arrayOfNumbers[inc] == arrayOfNumbersClone[dec])
                {
                    counter++;
                }
                else
                {
                }

            }
            if(counter<=0)Console.WriteLine("The array is not symmetric");
            else Console.WriteLine("The array is symmetric");

Aucun commentaire:

Enregistrer un commentaire