Program checkZIPS is working well with all the zip code except "BK 87946". When I entered BK 87946 the output was “Zip BK 87946 not found”. That means program is behaving very strangely. Please explain. I am attaching the program.
using System;
public
class CheckZIPS{
public static void Main(){
string[] zips = {"BF 45633", "GJ 76895", "BK 87946", "NM 38657"}; int x; string enterzip;Console.Write("Enter Zip code: ");
enterzip = Console.ReadLine();
x = Array.BinarySearch(zips, enterzip);
if(x < 0)Console.WriteLine("Zip {0} not found", enterzip);
elseConsole.WriteLine("Zip {0} was found at position {1}",
enterzip, x);
}
}
Posted Mar 10, 2007, 9:09 AM
Posted Mar 10, 2007, 2:01 AM
Array.Sort(zips);
Or you can use
x =
Array.IndexOf(zips, enterzip);Good Luck, Alex