这是我目前为止的内容:
这是我目前的进展:
namespace factorials
{
class Program
{
static void Main(string[] args)
{
int number;
do
{
Console.WriteLine("What non-negative integer do you want to factorial?");
while (!int.TryParse(Console.ReadLine(), out number))
Console.WriteLine("Please enter a whole number only");
calculate(ref number);
} while (number >= 0);
Console.WriteLine("Please enter a non-negative number");
}
static void calculate(ref int number)
{
int factorial;
int counter;
for (counter = number; counter <= number; counter++)
{
factorial = number * number;
Console.WriteLine("The factorial of {0} is {1}", number, factorial);
}
}
}
}
现在它只给出了数字的平方,而不是它们的阶乘。如何使程序重复输入次数,从而得出阶乘结果?
此外,我不确定是否有必要仅限于非负整数,但如果我想这样做,那么该部分只需在此处结束程序,而不是回到开始。