I cannot spot where my mistake is on my IF/ELSE
statement nested inside my for
loop. I did try to use a while
loop to get make my IF/ELSE
statement work, but it didn't work as expected.
Even my Console.Writeline
statement cannot capture the right price and size.
My code:
static void Main(string[] args)
{
string[] size = { "S", "M", "L", "X"};
decimal[] price = { 6.99M, 8.99M, 12.50M, 15.00M};
Console.WriteLine("Please enter a pizza size : ");
string pizzaSize = Console.ReadLine();
int i;
for (i = 0; i < size.Length; i++)
{
if (size[i] == pizzaSize)
{
Console.WriteLine("Your pizza size is " + pizzaSize + ". The price is " + price[i].ToString("C"));
} else
{
Console.WriteLine("Please enter a valid pizza size");
return;
}
}
Console.ReadKey();
}
Aucun commentaire:
Enregistrer un commentaire