two value for function

hello,guys,this code will take the angle & give you back the sin ,cos,tan,cot,with the taylor series but i dont know why it gives me back two value for each ?
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
using namespace std;
//char greeding(char lets[][100],const int letsrow);//using for explain the program and greeding.
//void setcolor(int backgroundcolor, int foregroundcolor);//set color of background.
void interface(double angle, char x);//using for showing the interface.
double power(double z,double g);//power function.
int factorial(int g);//calculate factorial.
double sin(double z);//counting the assignment of sinx.
double cos(double z);//counting the assignment of cosx.
double tan(double z);//counting the assignment of tan(x).
double cot(double z);//calculating the assignment of cotx.
void result();// using for showing result.
double z;
char answer;
double angle;
char x;
double w;

int main()
{
char x;
/*const int letssize = 100;
const int letsrow = 100;
char lets[letssize][letsrow] ={{'*','*','*','L','e','T',' ','s',' ','P','l','A','y','*','*','*'},
{'*','*','*','*','L','e','T',' ','s',' ','P','l','A','y','*','*'},
{'*','*','*','*','*','L','e','T',' ','s',' ','P','l','A','y','*'},
{'*','*','*','*','*','*','L','e','T',' ','s',' ','P','l','A','y'},
{'y','*','*','*','*','*','*','L','e','T',' ','s',' ','P','l','A'},
{'A','y','*','*','*','*','*','*','L','e','T',' ','s',' ','P','l'},
{'l','A','y','*','*','*','*','*','*','L','e','T',' ','s',' ','P'},
{'P','l','A','y','*','*','*','*','*','*','L','e','T',' ','s',' '},
{' ','P','l','A','y','*','*','*','*','*','*','L','e','T',' ','s'},
{'s',' ','P','l','A','y','*','*','*','*','*','*','L','e','T',' '},
{' ','s',' ','P','l','A','y','*','*','*','*','*','*','L','e','T'},
{'T',' ','s',' ','P','l','A','y','*','*','*','*','*','*','L','e'},
{'e','T',' ','s',' ','P','l','A','y','*','*','*','*','*','*','L'},
{'L','e','T',' ','s',' ','P','l','A','y','*','*','*','*','*','*'},
{'*','L','e','T',' ','s',' ','P','l','A','y','*','*','*','*','*'},
{'*','*','L','e','T',' ','s',' ','P','l','A','y','*','*','*','*'},
{'*','*','*','L','e','T',' ','s',' ','P','l','A','y','*','*','*'},};*/



//greeding(lets,letsrow );//using for explain the program and greeding.
interface(angle,x);//using for showing the interface.
result();// using for showing result.
cout << "Do you want to continue? \n";
cout << "Type Y to continue.\n";
cout <<" Any other key to stop.";
cout <<"your response-> \n";
cin >> answer;

if (answer=='y'||answer=='Y')//check for stop or continue.
{

while(answer=='y'||answer=='Y')//check for stop or continue.

{
interface(angle,x);//using for showing the interface.
result();// using for showing result.
cout << "Do you want to continue? \n";
cout << "Type Y to continue.\n";
cout <<" Any other key to stop.";
cout <<"your response-> \n";
cin >> answer;
}


}
else if((answer!='y')&&(answer!='Y'))
{
cout << "Thank you,Goodbye";
}


return 0;
}
/*void setcolor(int backgroundcolor, int foregroundcolor)
{
textbackground(backgroundcolor);
textcolor(foregroundcolor);
}*/
void interface(double angle,char x)//using for showing the interface.
{
double w;
cout << endl;
cout << "****** TRiGoNOMeTrY ****** \n";
cout << "Please enter an angle value -> \n";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(10);
cin >> angle;
system("PAUSE");
while((angle < 0.0000000000)|| (angle > 360.0000000000))//checking for area of input angle.
{
cout <<" you got wrong angle,try again!\n ";
cout << "****** TRiGoNOMeTrY ******\n ";
cout << "Please enter an angle value -> \n";
cin >> angle;
system("PAUSE");
}
cout << "Is your angle in Degree or Radian ? \n ";
cout << " Please type D ,if it is Degree. \n";
cout << " Please type R,if it is Radian. \n ";
cout << " your response -> \n";
cin >> x;// asking for degree or radian.
while ((x!='d')&&(x!='D')&&(x!='r')&&(x!='R'))//checking for wrong input of x.
{
cout<<"you got wrong response,enter again:\n";
cin >> x;
}
if ((x=='d')|| (x=='D'))
{

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(10);
z = angle*(0.0174532925);

cout << "your response-> D \n";
cout << angle <<" "<<"Degree = "<< z <<endl;

}
else if((x=='r')||(x=='R'))
{ while ((angle>6.29)||(angle<0.000000000))//checking for radian.
{
cout << "The value of the angle that you entered is more than the scope of radian,please enter again:\n";
cout <<"should be between (0.0000000000 - 6.2999999999)\n";
cout << "Please enter an angle value -> \n";
cin >> angle;
}
z=angle;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(10);
w = angle /(0.0174532925);
cout << "your response-> R \n";
cout << angle <<" "<<"Radian = "<< w <<endl;
}


};
double power(double z,double g)//power function.
{
double pow=1;
while(g >= 1)
{
pow *= z;
g--;

}
return pow;

}
int factorial(int g)//calculate factorial.
{
int result = 1;
while(g > 0)
{
result *= g;
g--;
}
return result;
}
double sin(double z)//counting the assignment of sinx.
{
double sinx;
double resultofsin= z ;
double g = 3;
double s = -1;

double temp = 1;
while(temp>=0.0000000000001)
{
temp = ((s)*(power(z,g)))/(factorial(g));
cout << temp << endl;
resultofsin += temp;
g += 2;
s *= -1;
}
sinx =z - resultofsin;

return sinx;
}
double cos(double z)//counting the assignment of cosx.
{
double cosx;
double resultofcos = z;
double o = 2;
double s = -1;

double temp = 1;
while(temp>=0.0000000000001)
{
temp = ((s)*((power(z,o))/(factorial(o))));
cout << temp << endl;
resultofcos += temp;
o += 2;
s *= -1;
}
cosx =1 - resultofcos;
return cosx;
}
double tan(double z)//counting the assignment of tan(x).
{
double tanx = 0;
tanx = sin(z)/cos(z);
if ( (tanx>1) || (tanx<-1) )
{
tanx=2;
return tanx;
}
else
{
return tanx;
}
}
double cot(double z)//calculating the assignment of cotx.
{
double cotx = 0;
cotx = cos(z)/sin(z);
if ( (cotx>1) || (cotx<-1) )
{
return 0;
}
else
{
return cotx;
}
}
void result()// using for showing result.
{
cout << " RESULT \n";
cout << "=================================\n";
cout << " (x)= "<< z <<" Radian \n";
cout << "sin(x)= "<< sin(z)<< endl;
cout << "cos(x)= "<<cos(z)<<endl;
if(tan(z)==2)
{
cout << "tan(x)= " << "infinity"<<endl;
}
else
{
cout << "tan(x)= "<<tan(z)<<endl;
}
if(cot(z)==0)
{
cout << "cot(x)= "<<"infinity"<<endl;
}
else
{
cout << "cot(x)= "<< cot(z) << endl;
}
cout << "=================================\n";


};

/*char greeding(char lets[][100],const int letsrow)//using for explain the program and greeding.
{
for (int i=0 ; i<letssize ; i++ )
{
for (int j=0; j<=letsrow;j++)
{
cout << lets[i][j];

}
cout << endl;
}


};*/
Last edited on
Please use code tags when posting code here.
ok mikey ,thank you for inform me,because i m new member so still didnt proved,do you know the answer?
Topic archived. No new replies allowed.