我正在尝试创建一个程序,它要求用户输入整数并在while循环中将它们相加,然后当输入负数时,循环结束,但由于某种原因我找不到添加方法向上用户添加到总数中的数字,它只显示小计旁边最初为 0 的总数(用户输入的金额)
int iNumber =0;
int iTotal = 0;
int iSubTotal = 0;
//Prompt user to enter two values
Console.WriteLine("Enter value you want to add to total value or a negative number to end the loop");
while (iNumber >= 0)
{
iSubTotal = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The Total is now " + iSubTotal + iTotal);
if (iNumber < 0)
{
Console.WriteLine("You have not passed the loop");
Console.WriteLine("The Total is now " + iTotal);
}
//Prevent program from closing
Console.WriteLine("Press any key to close");
Console.ReadKey();
}