//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!!"); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter