如何查找輸入了多少數字?C#如何找到輸入了多少數字?
static void Main(string[] args)
{
string x;
double t, s = 1;
while ((x = Console.ReadLine()) != null)
{
}
如何查找輸入了多少數字?C#如何找到輸入了多少數字?
static void Main(string[] args)
{
string x;
double t, s = 1;
while ((x = Console.ReadLine()) != null)
{
}
,以獲得數輸入爲雙,你會用double.TryParse Google here轉換「X」爲「T」,然後以某種方式採取行動。如果你想要更具體的東西,你需要分享你想要做的(預期輸入/預期輸出)。你的英語「輸入了多少數字」還不清楚。
static void Main(string[] args)
{
string x;
double t,tot=0, s = 1;
while ((x = Console.ReadLine()) != null)
{
if(double.TryParse(x,out t))
{
//t is now the number entered as a double -- process
tot+= t;
Console.WriteLine(s==1?"Please enter your second number":"The sum of your "+s.ToString()+" numbers is "+tot.ToString("N0"));
s++;
}else{
Console.WriteLine("You may only enter numbers. Please try again.\n");
}
}
對不起,我英語不好。 [鏈接](http://pastebin.com/YL80B9Qz)。它是我的代碼。例如,我輸入了「5」「4」「3」數字。結果是60。然後在下一行我需要顯示我爲這個例子輸入了多少數字,我需要顯示「3」 – Mantas
好的 - 我只是編輯我的答案,做我認爲你正在尋找的東西。那是你想要它做什麼? –
你的問題不清楚,請使用說明,輸入說明問題(在超過9個字的描述) – Sayse
你想x'轉換'多項並將其存儲在't'?或者驗證x是一個有效的數字? – user3185569