I'm a new at programming in C, and I seem to keep having syntax errors. I have written a function that tries to calculate the factorial of a number that the user entered into Main. Everything seems to work fine, except that I only get the number one (1) as an answer. I've pinpointed my problem to the for-loop within my function. Beyond this I can't seem to resolve the issue. Yes, I have worked on this for quite sometime now and yes it's part of my homework. I really want to know how to fix the problem, since I will have to fix on a test next time.
Thanks for any help.
Code:
#include <stdio.h>
int factorial(int);
int f, i;
int fact;
int main()
{
//Input factorial value
printf("This program finds the factorial of a number\n");
printf("Number to be factored: ");
scanf("%d",&fact);
//Print the results of the Function
printf("\n\n%d! equals: %d\n", fact, factorial(fact));
getchar();
getchar();
}
int factorial(int fact) { //function to find the factorial
int answer = 1;
/*for (i = fact; i <= 1; i = i -2) {
answer = answer * (i * (i - 1));
}*/
return answer;
}