#include <iostream>
	#include <cmath>

using namespace std;

int main() {
	// Define all variables required
	double sinTaylor,cosTaylor,Term,x;
	double const pi = 3.1459;
	int fact,sign,n,index,i;
	
	// Input statements
	cout << " Enter the Angle :"<<endl;
	cin >> x;
	x = pi*x/180;

	/* Initialize all variables , we have Term that holds the general term in the series
	fact to store the factorial of n , variable sign is to decide whether subsequent terms are 
	to be added or subtracted*/

	sinTaylor = 0.00;
	n = 1;
	fact =1;
	/* Index variable is to track the term number*/
	index =0;
	// sign decides if the subsequent terms are to be added or subtracted
	sign = pow(-1,index);	
	Term = pow(x,n)/fact;
	
	// While loop to compute the series
	while(Term > 0.00005) {
			sinTaylor = sinTaylor + (sign*Term);
			n = n+2;
			index++;
			fact =1;
			for(i=1;i<=n;i++) {
				fact = fact*i;
			}
			Term = (double)(pow(x,n)/fact);			
			sign = pow(-1,index);					
	}
	
	/* getting value of sine from cmath. You were NOT asked to do this but this is a good way of checking if you have got
	the correct answer*/
	cout<<" from cmath"<< sin(x) << endl;
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(4);
	cout<< " The sine of x:"<< sinTaylor<<endl;
	// Note for sin series n was initialized to 1 as we needed X as the first term, 1 is the first term
	// in cosine series so we initialize n as 0 here.
	n = 0;
	sign = 1;
	fact =1;
	index = 0;
	Term = (double)(pow(x,n)/fact);
	cosTaylor = 0.00;

	while(Term > 0.00005) {
			cosTaylor = cosTaylor + (sign*Term);
			n = n+2;
			index++;
			fact =1;
			for(i=1;i<=n;i++) {
				fact = fact*i;
			}
			Term = (double)(pow(x,n)/fact);			
			sign = pow(-1,index);					
	}
	/* getting value of sine from cmath. You were NOT asked to do this but this is a good way of checking if you have got
	the correct answer*/
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(4);
	cout<< " The cosine of x:"<< cosTaylor;
	return 0;
	
}
