Closed Thread
Results 1 to 8 of 8

Thread: how to make 1/0

  1. #1
    NicholasIT is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    76
    Rep Power
    0

    how to make 1/0

    mayb i have a condition that
    when 1/0
    then will cout infinity
    or the value will return to infinity ?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    NicholasIT is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    76
    Rep Power
    0

    Re: how to make 1/0

    Code:
    if(tanx =)    //what should i put in the condition ??
    	{
    	cout.width(10);
    	cout<<"Your Tangent Value is" <<" = " ;
    	cout.width(15);
    	cout<<"Infinity"<<endl;
    	}

  4. #3
    Join Date
    Jun 2010
    Location
    Vancouver, Eh.
    Posts
    4,020
    Blog Entries
    7
    Rep Power
    39

    Re: how to make 1/0

    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.

  5. #4
    NicholasIT is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    76
    Rep Power
    0

    Re: how to make 1/0

    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?

  6. #5
    NicholasIT is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    76
    Rep Power
    0

    Re: how to make 1/0

    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?

  7. #6
    Flying Dutchman's Avatar
    Flying Dutchman is offline Programming God
    Join Date
    Feb 2010
    Location
    ::1
    Posts
    821
    Rep Power
    13

    Re: how to make 1/0

    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.

  8. #7
    NicholasIT is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    76
    Rep Power
    0

    Re: how to make 1/0

    erm,thanks for ur advice
    however
    Code:
          string tabNames[3] = {"Cosecant", "Secant", "Cotangent"};
            double tabResult[3] = {cosecant, secant, cotangent};
    may i ask this coding is for ?
    and the looping is for?

  9. #8
    NicholasIT is offline Learning Programmer
    Join Date
    Apr 2010
    Posts
    76
    Rep Power
    0

    Re: how to make 1/0

    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

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I Want to Make an App
    By agnl666 in forum General Programming
    Replies: 4
    Last Post: 11-22-2010, 07:21 PM
  2. need help to make a OS
    By Axalto in forum Managed C++
    Replies: 34
    Last Post: 09-08-2010, 12:17 AM
  3. how to make +
    By omicron9194 in forum C and C++
    Replies: 0
    Last Post: 10-17-2009, 11:27 PM
  4. Make a Wish :)
    By sourlemon in forum Games
    Replies: 54
    Last Post: 01-30-2009, 04:42 PM
  5. How Much do you make?
    By Lop in forum The Lounge
    Replies: 11
    Last Post: 11-22-2006, 01:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts