這是我的代碼。我想讓用戶連續輸入任意數量的雙打,直到100次(但可以是用戶想要的次數但少於100次)。顯示所有輸入值的總和。在我的代碼中,我不知道如何讓用戶連續輸入數字(即時猜測你會有一個while循環)。 非常感謝!添加每個雙位數字的數字
Console.WriteLine("Enter double");
double.first = double.Parse(Console.ReadLine());
while(first != 0)
{
Console.WriteLine("Enter double");
int num = int.Parse(Console.ReadLine());
double sum;
while(num != 0)
{
double ten = num/10;
double tenth = Math.Floor(ten);
double oneth = num % 10;
sum = tenth + oneth;
Console.WriteLine("{0}", sum);
break;
}
first = double.Parse(Console.ReadLine());
}
就放在'while'陳述一個破發點,並通過它一步。此外,請查看['break break'](https://msdn.microsoft.com/en-us/library/adbctzc4.aspx)(與斷點完全不同)。 –
這是一項家庭作業嗎? – Kevin
目前還不清楚你在問什麼。當我閱讀「顯示單獨和一起輸入的所有值的總和」時,我認爲你想總結所有輸入的雙打(一起),並且要總結每個輸入的雙倍(單獨)的數字。這是你問的嗎? – Shar1er80