Jamie Dalley

Jamie Dalley

  • 2.1k
  • 16
  • 5.2k

What is wrong with this linear search?

Jan 23 2013 7:13 AM
Basically I am working on my assignment and i need to make my code read a number then check  to see if the number is in an array I created. This is the code at the moment starting from where i create the array
 Console.WriteLine("Press enter to see question 7");
            Console.ReadKey();
            int MaxValue;
            int RandomNumber;
            Random MyRandom;
            MaxValue = 20;
            MyRandom = new Random();
            RandomNumber = MyRandom.Next(MaxValue);

            int[] firstArray = new int[10];
            for (int i = 0; i < 10; i++)
            {
                RandomNumber = MyRandom.Next(MaxValue);
                firstArray[i] = RandomNumber;
            }
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Item {0} in the array is {1}", i, firstArray[i]);
            }
            //8
            Console.WriteLine("Press enter to see question 8");
            Console.ReadKey();
            Console.WriteLine("The lowest number in the array is {0}", firstArray.Min());
            //9
            int j;
            for (j = 0; j < 20; j++)
            {
                if (linear_search(j, 7, firstArray))
                    System.Console.WriteLine(j + "if found in the array");
                else
                    System.Console.WriteLine(j + "is not found in the array");
            }
The problem I have at the moment is it says "the name "linear_search" does not exist in the current context". Also I know there are probably problems with the code anyway, since i'm not really sure how to use linear searches and can't find anywhere that explains it properly. I know the code at the moment isn't asking for input, and is just looking for 7 in the code, but that's just for while i make it work.


Answers (3)