Maha

Maha

  • NA
  • 0
  • 328.1k

C# Program CheckZIPS

Mar 9 2007 5:57 PM

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);

else

Console.WriteLine("Zip {0} was found at position {1}",

enterzip, x);

}

}


Answers (2)