I have to create the sin function from scratch in my Comp Sci class, and I am getting close to a solution. However, I am still having a few problems. If I put in a value of .5PI or less it works, but otherwise I get the incorrect result. Here is the code I have so far:
double i=1; double sinSoFar = 0; int term = 1; while(i >= .000001) { i = pow(-1, term + 1) * pow(sinOf, 2*term-1) / factorial(2*term-1); sinSoFar=sinSoFar + i; term++; }
Like Federico pointed, the problem probably is in your factorial() or pow(). I ran a test that worked fine replacing your functions with the pow() function provided in the Math class, and this factorial():