So I am trying to solve this, but even if user enters zipCode that is not in array the program still says Console.WriteLine("We deliver there it will cost you {0}", answerPrice);..........................
I dont get it, i looked at and looked and just cant find the problem
int[] ZipCode = { 28303, 12526, 72334, 17811, 86251, 56214, 72334, 87243, 71422, 72343 };
double[] prices = { 0.10, 2.0, .50, .25, .15, .75, 1.0, 7.0, 15.0, 5.0 };
double answerPrice = 0;
bool Found = true;
Console.WriteLine("Enter the zip:");
string readLine = Console.ReadLine();
int userInput = Convert.ToInt32(readLine);
for (int index = 0; index < ZipCode.Length; ++index)
{
if (userInput == ZipCode[index])
{
Found = true;
answerPrice = prices[index];
}
}
if(Found)
Console.WriteLine("We deliver there it will cost you {0}", answerPrice);
else
Console.WriteLine("Sorry we don't deliver it");
Loading
Jignesh TrivediPosted Jan 19, 2012, 10:50 PM
you find ans. for your post is good..
ihave some suggetion on above screen.
try to use generic list instred of array.
try to Linq to find out value from generic list.
because its good practice.
Prime bPosted Jan 19, 2012, 6:42 PM