I am very confused on how to change a for loop into a foreach loop. I have a piece of code that is similar to a program that I working on to implement a foreach loop into.
{
class Program
{
static void Main(string[] args)
{
int entered = 0;
string ayethatsprettygood;
bool dothesalamander = false;
string[] zipcode;
zipcode = new string[10] {"12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210" }; //This array is the zipcodes
double[] prices;
prices = new double[10] { 2.40, 3.00, 3.50, 4.00, 4.50, 5.00, 5.25, 5.75, 6.10, 10.003 }; //This array is the prices
Console.Write("Enter a Zipcode:");
ayethatsprettygood = Console.ReadLine();
for (int i = 0; i < zipcode.Length; i++) {
if (ayethatsprettygood == zipcode[i])
{
dothesalamander = true;
entered = i;
break;
}
}
if (dothesalamander == true)
{
Console.WriteLine("We deliver to this zipcode {0} the price of delivery is {1}", zipcode[entered], prices[entered].ToString("C2"));
}
else
Console.WriteLine("We don't deliver to this zipcode {0}",ayethatsprettygood);
{
class Program
{
static void Main(string[] args)
{
int entered = 0;
string ayethatsprettygood;
bool dothesalamander = false;
char[] pizzasize;
pizzasize = new char[4] { 'S', 'M', 'L', 'X' }; //This array is the zipcodes
double[] pizzaprices;
pizzaprices = new double[4] { 6.99, 8.99, 12.50, 15.00 }; //This array is the prices
Console.Write("Enter a Pizza Size:");
ayethatsprettygood = Console.ReadLine();
foreach(char pizzaprice in pizzaprices )
{
if (ayethatsprettygood == pizzaprice)
{
dothesalamander = true;
entered = pizzaprice;
break;
}
}
if (dothesalamander == true)
{
Console.WriteLine("The size of the pizza is {0} the price is {1}", pizzasize[entered], pizzaprices[entered].ToString("C2"));
}
else
Console.WriteLine("Sorry you entered an invalid size {0}", ayethatsprettygood);
}
}
}
if anyone could help me complete this program it would be really helpful! Thank You!