//Write code that prompts the user to make a choice for a pizza size - S, M, L, or X - and then displays the price as
//$6.99, $8.99, $12.50, or $15.00, accordingly.
//Display an error message if the user enters an invalid pizza size.
//(Note: to read a char from the user use the following: ReadKey().KeyChar from the Console class).
char[] sizes = { 'S', 'M', 'L', 'X' };
double[] prices = { 6.99, 8.99, 12.50, 15, 00 };
Console.Write("Enter the size of the pizza: ");
char size = Console.ReadKey().KeyChar;
bool valid = false;
for(int i = 0; i < sizes.Length; i++)
{
if (sizes[i] == size)
{
Console.WriteLine($"\nThe price is: {prices[i]}");
valid = true;
}
}
if (!valid)
{
Console.WriteLine("\nInvalid pizza size!!");
}
Comments