2
即時通訊這只是一個初學者和即時通訊製作一個貨幣轉換器,其中輸入和驗證一個整數,並輸入和驗證匯率。即時通訊如何計算以前輸入的兩個驗證值的匯率問題。這裏是我迄今爲止所做的代碼,這也是一個控制檯應用程序。貨幣轉換器幫助c#
static void Main(string[] args)
{
wholeNumber();
exhangeNumber();
}
private static void exhangeNumber()
{
double evalue;
bool valid;
Console.WriteLine("please enter an exchange rate");
do
{
try
{
evalue = double.Parse(Console.ReadLine());
Console.WriteLine("the exchange rate entered is: {0:F2}", evalue);
valid = true;
}
catch
{
Console.WriteLine("invalid Exchange rate please try again");
valid = false;
}
}
while (valid == false);
Console.ReadLine();
}
private static void wholeNumber()
{
int ivalue;
bool valid;
Console.WriteLine("please enter a whole number");
do
{
try
{
ivalue = int.Parse(Console.ReadLine());
Console.WriteLine("the valuse you have entered is : {0:F0}", ivalue);
valid = true;
}
catch
{
Console.WriteLine("this is not a whole number please try again");
valid = false;
}
} while (valid == false);
}
}
}
+1但是補充的內容解析/的TryParse,它是完美的 – Steve
@Steve - 當然,我就節省,對於一個幾年下來的線時,OP回首自己的代碼來提高它:) – Sayse
@Steve - 如果它可以改善任何更多的隨時讓我知道,謝謝 – Sayse