Skip to content
Loading
  • Jenith Thakkar
    0
    You can do that like this way 

    namespace ConsoleAppForZip
    {
    class Program
    {
    public static void Main(string[] args)
    {
    string[] zipCode = { "40475-150", "40473-151", "40476-152", "40481-153", "40484-158", "40481-153", "40484-158", "40486-150", "40488-157", "40489-155" };
    int menuchoice = 0;
    while (menuchoice != 7)
    {
    Console.WriteLine("Menu");
    Console.WriteLine();
    Console.WriteLine("1. Print all zip codes");
    Console.WriteLine("2. Print all zip codes and delivery charges");
    Console.WriteLine("3. Search for a zip code");
    Console.WriteLine("4. Exit");
    menuchoice = int.Parse(Console.ReadLine());
    switch (menuchoice)
    {
    case 1:
    ListZip(zipCode, menuchoice);
    break;
    case 2:
    ListZip(zipCode, menuchoice);
    break;
    case 3:
    ListZip(zipCode, menuchoice);
    break;
    case 4:
    break;
    default:
    Console.WriteLine("Sorry, invalid selection");
    break;
    }
    Console.ReadLine();
    }
    }
    public static void ListZip(string[] zipArray, int menuchoice)
    {
    if (menuchoice == 1 || menuchoice == 2)
    {
    for (int x = 0; x < zipArray.Length; ++x)
    {
    string[] ZipDetails = zipArray[x].Split('-');
    if (menuchoice == 1)
    Console.WriteLine("ZipCode is:" + ZipDetails[0].ToString());
    if (menuchoice == 2)
    Console.WriteLine("ZipCode is:" + ZipDetails[0].ToString() + " and Delivery Price is:" + ZipDetails[1].ToString());
    }
    }
    else
    {
    Console.WriteLine("Search the Zip Code");
    var ZipData = Console.ReadLine();
    bool ZipMatched = false;
    for (int x = 0; x < zipArray.Length; ++x)
    {
    string[] ZipDetails = zipArray[x].Split('-');
    if (ZipDetails[0] == ZipData)
    {
    ZipMatched = true;
    Console.WriteLine("ZipCode is:" + ZipDetails[0].ToString() + " and Delivery Price is:" + ZipDetails[1].ToString());
    }
    }
    if (!ZipMatched)
    {
    Console.WriteLine("the company does not deliver to the requested zip code.");
    }
    }
    }
    }
    }
    0