我完全是C#的新手,我完全失去了。我需要做的是儘可能多地輸入數字並繼續輸入,但是當輸入值爲「0」時,即將所有輸入的數字全部加起來。在C#中輸入0時,添加輸入的數字的總和?
這是我的計劃:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Activity2
{
class Program
{
static void Main(string[] args)
{
int n, sum, x = 0;
do
{
Console.WriteLine("Enter a Number: ");
n = int.Parse(Console.ReadLine());
}
while (n != 0);
{
sum = n + x;
x = n;
n = sum;
Console.WriteLine("The sum is: " + n);
}
Console.ReadLine();
}
}
}
您可能會考慮隨時添加它們,並在輸入'0'時打印總數。 – frasnian 2014-11-22 15:48:45