0
編輯 -謝謝格蘭特&蒂姆爲先前的答案,但它看起來不像我目前的代碼能夠轉,輸出成十進制形式怎樣才能讓用戶顯示器的輸入爲十進制c#腳本錯誤「Line3是一個'變量',但像一種方法使用 - 幫助瞭解
Console.WriteLine("*************** Get Mileage***************");
Console.WriteLine("");
Console.WriteLine("Enter the Gas Mileage:");
line3 = Console.ReadLine();
if (int.TryParse(line3, out val))
{
double mileage = Convert.ToDouble(line3());
Console.WriteLine("Your car MPG is: " + mileage.ToString());
Console.WriteLine();
Console.WriteLine("");
Console.WriteLine("*************** Program Termination***************");
Console.WriteLine("");
Console.WriteLine("Thank you. Press any key to terminate the program...");
}
else
{
Console.WriteLine("Please only enter a interger, Please Close and try again");
Console.ReadLine();
}
謝謝你,但它並不像我當前的代碼能夠關閉輸出爲十進制形式。我如何將用戶顯示的輸入作爲小數? – Mckenzo101 2014-11-02 23:41:46
如果他們輸入一個十進制值,那麼'int.TryParse'將會失敗。改爲使用'decimal.TryParse'(或'double.TryParse')。 – 2014-11-03 00:25:29