1. problem function Sin()

i have wrote function Sin(), didn'd use math in libary, but when it run the result error, can you help me? fix it thanks very much.
sin(x)=Tn((-1)^k )*(x^2k+1)/(2k+1)!

Code:
```#include <iostream>
using namespace std;

double gt(double d){
if(d==1||d==0)return 1;
return d*gt(d-1);
}
//
double power(double a, int b)
{
double c=1;
for (int h=0; h<b; h++) c*=a;
return c;
}
//
double Mysin(int x){
double Sum=0;
for(int i=1;i<=10;i++){
double tmp=gt(2*i+1);
Sum+=(power(-1,i)*(power(x,2*i+1)))/tmp;
}
return Sum;
}
void main(){
//MySin M;
int x;
cin>>x;
cout<<Mysin(x);
}```

2. How does it not work?

Note that the return type of the global main function is int, not void.

3. it have run, but result error, can you help me ? void ? main<--

4. The first term of sin(x) should be x, not -x. The second term of sin(x) should be -x^3/6, not x^3/6. And so on.

5. thanks 2 you. but i dont use -x, and -x^3/6, not x^3/6.<---i dont understand

6. Originally Posted by llynx
thanks 2 you. but i dont use -x, and -x^3/6, not x^3/6.<---i dont understand
Oh, you're right. You have -x^3/6 correct, you just don't have the x term at all. i needs to start at 0, if you're going to use the 2i+1 form.

7. when i run result still error, if i =0; you help me? thanks
Code:
```#include <iostream>
using namespace std;

double gt(double d){
if(d==1||d==0)return 1;
return d*gt(d-1);
}
//
double power(double a, int b)
{
double c=1;
for (int h=0; h<b; h++) c*=a;
return c;
}
//
double Mysin(int x){
double Sum=0;
for(int i=0;i<10;i++){
double tmp=gt(2*i+1);
Sum+=(power(-1,i)*(power(x,2*i+1)))/tmp;
}
return Sum;
}
void main(){
//MySin M;
int x;
cin>>x;
cout<<Mysin(x);
}```

8. Well, the program you have doesn't compile:
Code:
`H:\temp.cpp:24: error: `main' must return `int'`
changing that gives something that does what I expect. (Notice that I do not expect to get sin(x) out of this program; 10 terms of the series is just not enough if x is even a little bit large (like, say, 10).)

9. your first term is negative because you start your array at one instead of zero (-1 ^ 1 = -1). so you need to add or subtract 1 from i when you use it as an exponent in that first part of the formula.

10. H:\temp.cpp:24: error: `main' must return `int'
i didn't know u use compler what, but i use visual C++, it still good run, but err result
i demo 10, realy as 100 .
your first term is negative because you start your array at one instead of zero (-1 ^ 1 = -1). so you need to add or subtract 1 from i when you use it as an exponent in that first part of the formula.
but -1^1=-1 yes right, i need it, but result error why ? in where ?

11. Originally Posted by llynx
i demo 10, realy as 100 .
I have no idea what this sentence is supposed to mean. If you want your code to accurately compute sin(x), then you will need in certain circumstances to take more than 10 terms of your series. You should then go until the value added on is smaller than your desired tolerance.
Originally Posted by llynx
but -1^1=-1 yes right, i need it, but result error why ? in where ?
This was from your original code where you started in the wrong place.

12. i have add function check(). you can clear it, in -1^1=1. thanks tabstop
Code:
```#include <iostream>
using namespace std;

double gt(double d){
if(d==1||d==0)return 1;
return d*gt(d-1);
}
//
double power(double a, int b)
{
double c=1;
for (int h=0; h<b; h++) c*=a;
return c;
}
int check(int n){
return (n%2)==0?1:-1;
}
//
double Mysin(int x){
double Sum=0;
double tmp=0;
for(int i=1;i<10;i++){
tmp=gt(2*i+1);
Sum+=(check(i+1)*(power(x,2*i+1)))/tmp;
}
return Sum;
}
int main(){
//MySin M;
int x;
cin>>x;
cout<<Mysin(x);
return 0;
}```