Sin function without using <cmath> sin()

Hey,

A portion of my assignment has me stuck, we've been asked to calculate the sin function without using the <cmath> command sin(). We were given an example code that should have worked, but I can't seem to get it. Whenever I run what I have, it asks for the variables then ends the program. This is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main()
{
  double sum = 0;
                double i=0;
                double s = 1;
                double x = 0;
                const double pi = 3.14159;
                
                cout<<"Please enter the value of x (angle) between -pi and +pi that you would like to take the sin of: ";
                cin>>x;
                while((x < -pi)||(x > pi))
                {
                    cout<<"Invalid entry for x, Please enter the value of x (angle) between -pi and +pi: ";
                    cin>>x;
                }
                for(i=0; i<10; i++)
                {
                    long double r=1;
                    for(int k=1; k<(2*i+1);k++)
                    {
                        r = r*k;
                    }
                    double x=0;
                    s = (pow(-1.0,i)*pow(x,(2.0*i+1)))/r;
                    
                    sum = sum + s;
}
}
Topic archived. No new replies allowed.