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:
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
int main()
{
double sum = 0;
double i=0;
double s = 1;
double x = 0;
constdouble 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++)
{
longdouble 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;
}
}