Thread: calculating cos

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    calculating cos

    ok to really surprise my mom im doing all the basic windows
    application (dont ask wut)
    ok now im having a problem with the calculator
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    int x;
    int y;
    int input;
    do{
    cout<<"1. multiply\n";
    cout<<"2. devide\n";
    cout<<"3. addition\n";
    cout<<"4. subtraction\n";
    cout<<"5. percentage\n";
    cout<<"6. cos&sin\n";
    cout<<"please provide the number listed\n";
    cin>> input;
    switch ( input )
    {
    case 1:
    cout<<"please provide 2 numbers to be multiplied\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x*y );
    cin.get();
    break;
    case 2:
    cout<<"please provide 2 numbers to be devided\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x/y );
    cin.get();
    break;
    case 3:
    cout<<"pls provide 2 numbers to be added\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x+y );
    cin.get();
    break;
    case 4:
    cout<<"pls provide 2 numbers to be subtracted\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x-y );
    cin.get();
    break;
    case 5:
    cout<<"pls provide 2 numbers to percented\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x%y );
    cin.get();
    break;
    case 6:
    cout<<"pls provide 2 numbers to be cos\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( cos(x, y );
    cin.get();
    break;
    }
    }while(input!=4);
    }

    but how do i do cos i dont get it

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Try using indentation.

    For cos you need to include <cmath>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    }while(input!=4);
    Maybe you want to make that whatever number you want to use for "quit"? Right now 4 invokes Subtraction.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    sine, cosine, and tangent (sin(), cos(), and tan()) require one argument - an angle. The angle is measured in radians. That argument should be a double (since you will be using pi in any sensible angle), and the return value of sin(), cos() and tan() is a double.

    A rewiew of one's trigonometric ratios might help.

    And the little 'percentage' operator (modulus) returns the remainer of a division. ie, 5 % 3 = 2 (Since 5 / 3 = 1r2)

    Also keep in mine you're using integers the whole way through. The user will not be able to enter a rational number, such as 1.526. I suggest looking into floating point numbers. Operations such as 20/9 will equal 2.
    Last edited by Cactus_Hugger; 09-27-2005 at 10:23 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    ok im thirteen anyone want to dumb it down

  6. #6
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Ok in your case, you probably want to find the sin and cosin of (x)
    in degrees rather than radians.


    1 radian is equal to 180/pi degrees, i.e. about 57.3 degrees.

    Therefore in order to use this in your calculator all you have to do is something like the following.


    Code:
    #include<iostream>
    #include<math.h>
    using namespace std;
    {
       double x;  
       cin>>x;
      
       x=x/57.3;
    
    
       cout<<sin(x);
       cout<<cos(x);
    
       .....
    }
    sin (x) is also defined as the infinite sum of:

    Code:
     
    x  -    x^3    +  x^5   -  x^7 + 
            -----     -----   -----    ....
              3!      5!         7!
    However, in your case you probably don't need to worry about this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculating : high numbers
    By MiraX33 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 11:08 PM
  2. calculating sin, cos, and tangent function
    By rcastel2 in forum C++ Programming
    Replies: 12
    Last Post: 02-23-2006, 01:32 PM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. sin() and cos() that use degrees
    By dwks in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 04:29 PM
  5. Taking input while calculating
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-12-2002, 04:47 PM