我的程序必须将前一个输入的号码添加到下一个号码中。这是我到目前为止,我被卡住了。它将我输入的数字相加,但我不明白我必须如何验证以前的一个数字。如何将用户输入添加在一起
static void Main(string[] args)
{
const int QUIT = -1;
string inputStr;
int inputInt = 0;
do
{
Console.Write("Type a number (type -1 to quit): ");
inputStr = Console.ReadLine();
bool inputBool = int.TryParse(inputStr, out inputInt);
if (inputBool == true)
inputInt += inputInt;
Console.WriteLine("Sum of the past three numbers is: {0}", inputInt);
} while (inputInt != QUIT);
}
由于可能有无限多个条目,我不知道如何正确使用数组。
使用[表](http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx) – Axis 2013-05-06 19:58:06
这是不清楚你想要做什么;如果你有“无限数量的条目”,你是否试图将所有这些数字相加?最后三个?每组三个? – 2013-05-06 20:08:00