我开始学习 C#,目前,变量并没有像我希望的那样更新。
string Carpet,
tempCarpet;
Double carpetPrice;
do{
Console.WriteLine("What type of carpet do you want: ");
Console.Write("1. Berber ($3.75) | 2. Plush ($4.62) | 3. Barbed ($9.98)");
tempCarpet = Console.ReadLine();
if (tempCarpet == "1") {
Carpet = "Berber";
carpetPrice = 3.75;
} else if (tempCarpet == "2") {
Carpet = "Plush";
carpetPrice = 4.62;
} else if (tempCarpet == "3") {
Carpet = "Barbed";
carpetPrice = 9.98;
} else
Console.WriteLine("Invalid Selection.");
}while(tempCarpet != "1"|tempCarpet != "2"|tempCarpet !="3");
Console.WriteLine("The Carpet" + Carpet + "costs {0:C}", carpetPrice);
` 出现错误,提示使用未分配的局部变量。我希望它采用这种格式,因为我想要选择人们想要的“地毯”。有谁知道这个问题的解决方案?