Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

brassfish89

sin not right?

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, im making a calculator program and it's saying that sin(45) is: 0.850904 when the windows calculator says it is: 0.70710678118654752440084436210485 here is the code:
  
#include <iostream>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[])
{
  while(1)
  {
    int input=0;
    double number=0.0f;
    double answer=0.0f;
    cout<<"What would you like to calculate?\n"
    "1. sine\n"
    "2. cosine\n"
    "3. tangent\n"
    "4. arcsine\n"
    "5. arccosine\n"
    "6. arctangent\n"
    "7. square root\n";
    cin>>input;
    cout<<"What number do you want to perform the operation on? ";
    cin>>number;
    switch(input)
    {
        case 1:
            answer=sin(number);
        break;
        case 2:
            answer=cos(number);
        break;
        case 3:
            answer=tan(number);
        break;
        case 4:
            answer=asin(number);
        break;
        case 5:
            answer=acos(number);
        break;
        case 6:
            answer=atan(number);
        break;
        case 7:
            answer=sqrt(number);
    }
    cout<<"Answer: "<<answer<<endl;
    cout<<"Press 0 or 1 to continue\n";
    cin>>input;
    if(input==0)
        break;
    system("cls");
  }
  cin.get();
  return 0;
}
   
thx brassfish edit: put code tags instead of source tags
doh, nuts. Mmmm... donuts My website [edited by - brassfish89 on April 29, 2003 8:31:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
You''re probably giving the function degrees when they take radians. To do the conversion, multiply number by (3.14159/180) before passing it to the trig function.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!