mayb i have a condition that
when 1/0
then will cout infinity
or the value will return to infinity ?
7 replies to this topic
#1
Posted 30 July 2010 - 03:58 AM
|
|
|
#2
Posted 30 July 2010 - 04:08 AM
if(tanx =) //what should i put in the condition ??
{
cout.width(10);
cout<<"Your Tangent Value is" <<" = " ;
cout.width(15);
cout<<"Infinity"<<endl;
}
#3
Posted 30 July 2010 - 05:07 AM
The code to catch floating point divisions by zero involves fpe catches and pragmas I'm not willing to dig up, the most simple way you can handle it is to check if the divisor is zero in the first place!
What example code throws the infinity error?
What example code throws the infinity error?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#4
Posted 30 July 2010 - 05:30 AM
void allResult2(double inputX)
{
double sinx,cosx,tanx;
double cosecant,secant,cotangent;
bool error=true;
sinx=sinxFunc(inputX);
cosx=cosFunc(inputX);
tanx=tanFunc(inputX);
cout.precision(7); //set decimal
cout.setf(ios::fixed); //display all numb
if(sinx ==0 || sinx==-0||cosx==-0|| cosx ==0 ||tanx==-0 || tanx ==0)
{
error =true; //cannot be zero
}
cosecant=1 / sinx;
secant= 1 / cosx;
cotangent= 1 / tanx;
cout<<"--------------------------------------------------"<<endl;
cout<<"\t Your Result "<<endl;
cout<<"--------------------------------------------------"<<endl;
if(error ==true)
{
cout.width(10);
cout<<"Your Cosecant Value is " <<" = " ;
cout.width(20);
cout<<"Infinity"<<endl;
}
else
{
cout.width(10);
cout<<"Your Cosecant Value is " <<" = " ;
cout.width(20);
cout<<cosecant<<endl;
}
if(error ==true)
{
cout.width(10);
cout<<"Your Secant Value is " <<" = " ;
cout.width(20);
cout<<"Infinity"<<endl;
}
else
{
cout.width(10);
cout<<"Your Secant Value is " <<" = " ;
cout.width(20);
cout<<secant<<endl;
}
if(error ==true)
{
cout.width(10);
cout<<"Your Cotangent Value is " <<" = " ;
cout.width(20);
cout<<"Infinity"<<endl;
}
else
{
cout.width(10);
cout<<"Your Cotangent Value is " <<" = " ;
cout.width(20);
cout<<cotangent<<endl;
}
cout<<"---------------------End--------------------------"<<endl;
system("pause");
}//display result cot,cose,sec
hmm,i tried to code like this ,but its not work ,all return infinity for me @@
any clues?
#5
Posted 30 July 2010 - 05:30 AM
void allResult2(double inputX)
{
double sinx,cosx,tanx;
double cosecant,secant,cotangent;
bool error=true;
sinx=sinxFunc(inputX);
cosx=cosFunc(inputX);
tanx=tanFunc(inputX);
cout.precision(7); //set decimal
cout.setf(ios::fixed); //display all numb
if(sinx ==0 || sinx==-0||cosx==-0|| cosx ==0 ||tanx==-0 || tanx ==0)
{
error =true; //cannot be zero
}
cosecant=1 / sinx;
secant= 1 / cosx;
cotangent= 1 / tanx;
cout<<"--------------------------------------------------"<<endl;
cout<<"\t Your Result "<<endl;
cout<<"--------------------------------------------------"<<endl;
if(error ==true)
{
cout.width(10);
cout<<"Your Cosecant Value is " <<" = " ;
cout.width(20);
cout<<"Infinity"<<endl;
}
else
{
cout.width(10);
cout<<"Your Cosecant Value is " <<" = " ;
cout.width(20);
cout<<cosecant<<endl;
}
if(error ==true)
{
cout.width(10);
cout<<"Your Secant Value is " <<" = " ;
cout.width(20);
cout<<"Infinity"<<endl;
}
else
{
cout.width(10);
cout<<"Your Secant Value is " <<" = " ;
cout.width(20);
cout<<secant<<endl;
}
if(error ==true)
{
cout.width(10);
cout<<"Your Cotangent Value is " <<" = " ;
cout.width(20);
cout<<"Infinity"<<endl;
}
else
{
cout.width(10);
cout<<"Your Cotangent Value is " <<" = " ;
cout.width(20);
cout<<cotangent<<endl;
}
cout<<"---------------------End--------------------------"<<endl;
system("pause");
}//display result cot,cose,sec
hmm,i tried to code like this ,but its not work ,all return infinity for me @@
any clues?
#6
Posted 30 July 2010 - 06:15 AM
This should work.
void allResult2(double inputX) {
double sinx;
double cosx;
double tanx;
double cosecant;
double secant;
double cotangent;
bool error = false; // no errors, yet
sinx = sinxFunc(inputX);
cosx = cosFunc(inputX);
tanx = tanFunc(inputX);
cout.precision(7); //set decimal
cout.setf(ios::fixed); //display all numb
if (sinx == 0 || sinx == -0 ||
cosx == 0 || cosx == -0 ||
tanx == 0 || tanx == -0)
{
error = true; //cannot be zero
}
cosecant = 1 / sinx;
secant = 1 / cosx;
cotangent = 1 / tanx;
cout << "--------------------------------------------------" << endl;
cout << "\t Your Result " << endl;
cout << "--------------------------------------------------" << endl;
string tabNames[3] = {"Cosecant", "Secant", "Cotangent"};
double tabResult[3] = {cosecant, secant, cotangent};
if (error) {
for (int i = 0; i < 3; i++) {
cout.width(10);
cout << "Your " << tabNames[i] << " value is = ";
cout.width(20);
cout << "Infinity" << endl;
}
} else {
for (int i = 0; i < 3; i++) {
cout.width(10);
cout << "Your " << tabNames[i] << " value is = ";
cout.width(20);
cout << tabResult[i] << endl;
}
}
cout << "---------------------End--------------------------" << endl;
cin.get();
}
Edited by Flying Dutchman, 30 July 2010 - 06:18 AM.
fixed indents
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#7
Posted 30 July 2010 - 06:31 AM
erm,thanks for ur advice
however
may i ask this coding is for ?
and the looping is for?
however
string tabNames[3] = {"Cosecant", "Secant", "Cotangent"};
double tabResult[3] = {cosecant, secant, cotangent};
may i ask this coding is for ?
and the looping is for?
#8
Posted 30 July 2010 - 06:44 AM
erm,sorry ,i get what u did edy =) sory in rush to reply you...
this is my result coding,however,it cannot work @@it still showing the weird result when tangent degree 90 ,270,450,630
void allResult(double inputX) //display sin,cos,tang
{
double sinx,cosx,tanx;
cout.precision(7);
cout.setf(ios::fixed);
bool error =false; // no error
sinx=sinxFunc(inputX);
cosx=cosFunc(inputX);
tanx=tanFunc(inputX);
if(cosx == 0 || cosx == -0 )
{
error = true; //cannot be zero
}
cout<<"--------------------------------------------------"<<endl;
cout<<"\t Your Result "<<endl;
cout<<"--------------------------------------------------"<<endl;
string tabNames[3] = {"SinX", "CosX", "Tangent"};
double tabResult[3] = {sinx, cosx, tanx};
if (error)
{
for (int i = 0; i < 3; i++)
{
cout.width(10);
cout << "Your " << tabNames[i] << " value is = ";
cout.width(20);
cout << "Infinity" << endl;
}
} else
{
for (int i = 0; i < 3; i++)
{
cout.width(10);
cout << "Your " << tabNames[i] << " value is = ";
cout.width(20);
cout << tabResult[i] << endl;
}
}
cout<<"---------------------End--------------------------"<<endl;
cin.get();
system("pause");
}
void allResult2(double inputX)
{
double sinx,cosx,tanx;
double cosecant,secant,cotangent;
bool error = false; // no errors, yet
sinx = sinxFunc(inputX);
cosx = cosFunc(inputX);
tanx = tanFunc(inputX);
cout.precision(7); //set decimal
cout.setf(ios::fixed); //display all numb
if (sinx == 0 || sinx == -0 ||cosx == 0 || cosx == -0 ||tanx == 0 || tanx == -0)
{
error = true; //cannot be zero
}
cosecant = 1 / sinx;
secant = 1 / cosx;
cotangent = 1 / tanx;
cout << "--------------------------------------------------" << endl;
cout << "\t Your Result " << endl;
cout << "--------------------------------------------------" << endl;
string tabNames[3] = {"Cosecant", "Secant", "Cotangent"};
double tabResult[3] = {cosecant, secant, cotangent};
if (error)
{
for (int i = 0; i < 3; i++)
{
cout.width(10);
cout << "Your " << tabNames[i] << " value is = ";
cout.width(20);
cout << "Infinity" << endl;
}
}
else
{
for (int i = 0; i < 3; i++)
{
cout.width(10);
cout << "Your " << tabNames[i] << " value is = ";
cout.width(20);
cout << tabResult[i] << endl;
}
}
cout << "---------------------End--------------------------" << endl;
cin.get();
system("pause");
}
this is my result coding,however,it cannot work @@it still showing the weird result when tangent degree 90 ,270,450,630
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









