次のコードに問題があります。
class Program
{
public static void Progress(ProgressEventArgs e)
{
int result = e.getPartialResult;
int stack_value = e.getValue ;
double max = System.Convert.ToDouble(numbers[j]);
System.Convert.ToDouble(stack_value);
double percent = (stack_value / max) * 100;
Console.CursorLeft = 18;
Console.Write(result + " ");
Console.CursorLeft = 46;
Console.Write(System.Convert.ToInt32(percent) + "% ");
}
public static void Calculate(int number, int time=0)
{
Factorial Fact = new Factorial();
Fact.Progression += new Factorial.ProgressEventHandler(Progress);
Console.Write("\n" + "Partial results : ");
Console.CursorLeft = 35;
Console.Write("Progress : ");
int Result = Fact.CalculateFactorial(number, time);
Console.WriteLine(" ");
Console.WriteLine("The factorial of " + number + " is : " + Result);
Console.ReadLine();
}
static int j;
static int[] numbers;
public static void Main(string[] args)
{
int i=0;
bool ok = false;
numbers = new int[10];
Console.Write("Please insert wait time (0,1 or 2) : ");
int time = int.Parse(Console.ReadLine()) * 1000;
Console.Write("Please insert a number : ");
do
if (Console.ReadLine() != "")
{
i++;
numbers[i] = int.Parse(Console.ReadLine());
}
else
{
ok = true;
}
while (ok == false);
for (j = 1; j <= i; j++)
{
Calculate(numbers[j],time);
}
}
}
したがって、ここでは少し奇妙です... if(Console.Readline()!="") 条件から来ているようです。
したがって、このプログラムは複数の数値の階乗を計算することになっています。スタックの進行状況をパーセンテージで表示するために、遅延時間を与えます。
ランダムな時間を入力して 2 つの値のみを挿入すると、プログラムは機能しますが、最初の数値に対してのみです。2 つ以上の数値を入力すると、FormatException が処理されません。
条件を if(numbers[i]!=10) に置き換えると、プログラムは任意の数の値に対して機能しますが、10! 計算する必要があります。
この問題を処理するにはどうすればよいですか? 明らかな何かが欠けていますか?前もって感謝します!