0
class Program
{
    static void Main(string[] args)
    {
        string[] zips = { "1600", "1601", "1602","1603","1604","1605","1606","1607","1608","1609","1610"};
        double[] prices = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10 };
        string entryZip;
        int x;
        bool zipFound = false;
        Console.Write("Enter zip code: ");
        entryZip = Console.ReadLine();

        for( x = 0; x < zips.Length && !zipFound; ++x)
        {
            if (entryZip == zips[x])
                Console.Write("Delivery to {0} ok. ", entryZip);
            Console.WriteLine("Delivery charge is {0} ",prices[x].ToString("C"));
            zipFound = true;`enter code here`
        }
        if (!zipFound)
            Console.WriteLine("no delivery to {0}. ",entryZip);

        Console.ReadKey();
    }
}

}

//I cant understand why the zipFound is bool zipFound = false; //anyone can explain it to me thanks :)

  • I recommend stepping through with the [debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems). I also recommend reading Eric Lippert's [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). – ProgrammingLlama Apr 07 '20 at 08:23
  • 1
    Please share a [mcve] that does _not_ read from the console so we can be confident what the value of `entryZip` is. – mjwills Apr 07 '20 at 08:25
  • 1
    Note that the `zipFound = true;` should **almost certainly** be inside the `if` a few lines up. Otherwise there is no point this code being inside a loop (since it will only ever execute 0 or 1 times). – mjwills Apr 07 '20 at 08:27
  • `bool zipFound = false;` is there to ensure that you enter the loop. If you defaulted it to `true` the loop would never be entered. – mjwills Apr 07 '20 at 08:27

0 Answers0