我的程序必须将输入的前一个数字添加到下一个数字中。这就是我到目前为止所拥有的,我被卡住了。它将我输入的数字加起来,但我不明白如何验证以前的数字。
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);
}
由于可能有不定数量的条目,我不知道如何正确使用数组。