如果用戶輸入A,它將起作用,然後它們輸入B它會起作用,如果它們輸入E,它也會起作用。它也可以工作,但如果它們然後輸入A,則重新開始關閉程序。取決於用戶選擇什麼來確定輸出
const double COMMRATE = 0.10;
const double COMMRATE = 0.10;
string inputstring;
char response;
Console.Write("Do you want to Calculate Sales A or B or E...");
inputstring = Console.ReadLine();
response = Convert.ToChar(inputstring);
while (response == 'A')
{
Console.WriteLine("Enter amount of sales");
string salesStr = Console.ReadLine();
Console.WriteLine(Double.Parse(salesStr) * COMMRATE);
Console.WriteLine("Enter sales member to continue or Z to exit");
response = Convert.ToChar(Console.ReadLine());
}
while (response == 'B')
{
Console.WriteLine("Enter amount of sales");
string salesStr = Console.ReadLine();
Console.WriteLine(Double.Parse(salesStr) * COMMRATE);
Console.WriteLine("Enter sales member to continue or Z to exit");
response = Convert.ToChar(Console.ReadLine());
}
while (response == 'E')
{
Console.WriteLine("Enter amount of sales");
string salesStr = Console.ReadLine();
Console.WriteLine(Double.Parse(salesStr) * COMMRATE);
Console.WriteLine("Enter sales member to continue or Z to exit");
response = Convert.ToChar(Console.ReadLine());
}
我有同樣的問題。我可以從A開始,然後轉到B然後E,但是當我嘗試再次擊中A時,程序關閉。 – user770022 2010-09-09 04:42:52
@ randywhite30 - 檢查Val上面的答案,它包含循環以保持程序運行,直到您按下Z. – 2010-09-09 04:48:50
+1爲隨附的課程計劃。 @randy你沒有循環你的程序,你正在使用if語句這樣的循環。 – Val 2010-09-09 04:50:04