mayb i have a condition that
when 1/0
then will cout infinity
or the value will return to infinity ?
Code:if(tanx =) //what should i put in the condition ?? { cout.width(10); cout<<"Your Tangent Value is" <<" = " ; cout.width(15); cout<<"Infinity"<<endl; }
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?
Be sure to read the updated FAQ || Health is achieved through 10,000 different steps.
A textual description can be only part of your question, be sure to provide sample results, errors and your platform in the appropriate forums while asking.
Code: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?
Code: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?
This should work.
Code: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(); }
Last edited by Flying Dutchman; 07-30-2010 at 07:18 AM. Reason: fixed indents
A conclusion is where you got tired of thinking.
Code:#define class struct // All is public.
erm,thanks for ur advice
however
may i ask this coding is for ?Code:string tabNames[3] = {"Cosecant", "Secant", "Cotangent"}; double tabResult[3] = {cosecant, secant, cotangent};
and the looping is for?
erm,sorry ,i get what u did edy =) sory in rush to reply you...
Code: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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks