2
Answers

C# Program CheckZIPS

Maha

Maha

17y
2.6k
1

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)