Prime b

Prime b

  • NA
  • 810
  • 345.6k

Going over array

Jan 19 2012 6:41 PM
So I am trying to solve this, but even if user enters zipCode that is not in array the program still says Console.WriteLine("We deliver there it will cost you {0}", answerPrice);..........................
I dont get it, i looked at and looked and just cant find the problem

            int[] ZipCode = { 28303, 12526, 72334, 17811, 86251, 56214, 72334, 87243, 71422, 72343 };
            double[] prices = { 0.10, 2.0, .50, .25, .15, .75, 1.0, 7.0, 15.0, 5.0 };
            double answerPrice = 0;
            bool Found = true;


            Console.WriteLine("Enter the zip:");
            string readLine = Console.ReadLine();
            int userInput = Convert.ToInt32(readLine);

            for (int index = 0; index < ZipCode.Length; ++index)
            {
                if (userInput == ZipCode[index])
                {
                    Found = true;
                    answerPrice = prices[index];
                }

            }
            if(Found)
                Console.WriteLine("We deliver there it will cost you {0}", answerPrice);
            else
                Console.WriteLine("Sorry we don't deliver it");


Answers (2)