当用户输入209,312,414时,程序需要停止
本文关键字:程序 用户 输入 414时 | 更新日期: 2023-09-27 18:07:54
我需要程序在用户输入209,312,414时停止。我的while循环不工作,因为程序在继续。我用了不同的方法,但在最后循环继续,当我输入209,312,414时,它并没有停止。我接受其他的建议。
using System;
public class program
{
public static void Main()
{
const double PRICE209 = 12.99, PRICE312 = 16.77, PRICE414 = 109.07;
double price;
int stockNum;
Console.Write("Please enter stock number. ");
stockNum = Convert.ToInt32(Console.ReadLine());
while ((stockNum == 209) || (stockNum == 312) || (stockNum == 414))
{
if ((stockNum == 209) || (stockNum == 312) || (stockNum == 414))
{
if (stockNum == 209)
{
price = PRICE209;
Console.WriteLine("The price for item # {0} is {1}", stockNum, price.ToString("C"));
}
else if (stockNum == 312)
{
price = PRICE312;
Console.WriteLine("The price for item # {0} is {1}", stockNum, price.ToString("C"));
}
else if (stockNum == 414)
{
price = PRICE414;
Console.WriteLine("The price for item # {0} is {1}", stockNum, price.ToString("C"));
} // end of the else if statement
} // end the if statement
Console.Write("Please enter stock number. ");
stockNum = Convert.ToInt32(Console.ReadLine());
} // end the while loop
Console.WriteLine();
Console.WriteLine("press <enter> to terminate program");
Console.ReadLine();
}
}
将while循环设置为:
while ((stockNum != 209) && (stockNum != 312) && (stockNum != 414))