fairly new so please forgive the question. I've written a method to take a string, covert it to a number, and return a Factorial of that number. That works fine. Its calling the method and printing the result that is confusing me. Here is the code:
static void Main(string[] args)
{
Console.WriteLine("Type number to do factorial on..");
var calc = Fact(Console.ReadLine());
Console.WriteLine("The answer is " + calc);
}
private static string Fact(string numFact)
{
var number = 1;
int factorial = Convert.ToInt32(numFact);
for (int i = 1; i<= factorial; i++)
{
number *= i;
}
// Console.WriteLine(number); added to test it works
return numFact;
}
Can somebody help please? As you'll probably guess from looking, If I input 5, I get 5 returned.
return number;Also, change the function signature toprivate static int Fact(string numFact)numFactnumber from the method which you are passing to it.return number.ToString()