-1
using System; using System.Collections.Generic; using System.Linq;
using System.Text; using System.Threading.Tasks;
namespace Assignment12 {
class Program
{
static void Main(string[] args)
{
bool found;
string[] toppings = { "cheese", "pepperoni", "green pepper", "onion", "mushroom" };
double[] price = { 1.30, 1.90, 1.80, 1.70, 1.60 };
Console.WriteLine("Choose a topping: cheese, pepperoni, green pepper, onion or mushroom");
Console.WriteLine("Please type the topping that you want - exactly as it appears above:");
string order = Console.ReadLine();
Console.WriteLine("\nYou chose: " + order);
found = false;
for (int i = 0; i < 5; i++)
{
if (order.Equals(toppings[i]))
{
found = true;
}
}
if (!found)
{
Console.WriteLine("The product " + order + " was not found, please try again!!!!!!\n");
Console.WriteLine("Hit any key to close"); Console.ReadKey(true);
return;
}
// The problem is here with the local variable "price"
Console.WriteLine("The price of " + order + " is $" + price);
// I also tried 1.30, 1.90, 1.80, 1.70, 1.60 but still not working
Console.WriteLine("Hit any key to close"); Console.ReadKey(true);
}
}
}
@AnassElbekkari你是什麼意思的「不工作」?它顯示編譯錯誤,引發運行時異常還是給出錯誤的結果? –
謝謝。它現在有效。我使用了第一種解決方案。 – AnsBekk