Console.Clear();
string choice;
Console.WriteLine("Welcome to Costa coffee\n");
Console.WriteLine("1:> Latte\n2:> Cappuccino\n3:> Espresso\n4:> Double espresso");
Console.WriteLine("\nPlease select a coffee by pressing 1-4");
choice = Console.ReadLine();
if (choice == "1")
{
Console.WriteLine("\nYou have selected: latte");
}
if (choice == "2")
{
Console.WriteLine("\nYou have selected: Cappuccino");
}
if (choice == "3")
{
Console.WriteLine("\nYou have selected: Espresso");
}
if (choice == "4")
{
Console.WriteLine("\nYou have selected: Double espresso");
}
else if (choice !="1" || choice !="2" || choice !="3" || choice !="4")
{
Console.WriteLine("Incorrect value, please try again");
}
我試圖讓程序,如果選擇不等於1,2,3,4那麼它會顯示「不正確的值,請再試一次」然而,當我按下任何東西時仍然有效,但在按1,2,3或4時仍然顯示此錯誤消息。任何想法?C#if語句!=多個值的
它贏得了我做了嗎?如果你選擇了4,它會* *做到這一點,如果你選擇1,2或3.提示:你認爲「其他」是一種替代?如果哪個條件不符合,會發生什麼? (我建議使用switch語句,而不是,請介意你...) –
只是最後一個別的別人{你的東西}和鏈別的ifs。 – TheNoob
''選擇!=「1」&&選擇!=「2」&...' – Rob