I believe the problem is in your loop. For factorials, I think it is best to use a recursive method. I recommend reading this. If you scroll down a bit, you can find a nice example of a factorial...