LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2004, 09:46 PM   #1
CorDharel
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Rep: Reputation: 0
[c++]confused about cosinus


Hi all!

Could anyone tell me why my calculator shows the value "0.91354646" and my c++ program shows "0.424179"?

I wanted to try the functions in the class "cmath.h" but it didn't work how it seems

Code:
#include <iostream>
#include <cmath>

int main()
{

	float x;

	x = cos(24);

	printf("\n\nCos value of x: %f\n\n",x);

}
 
Old 03-05-2004, 10:16 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
The cos function takes its input in radians, your calculator is using degrees.
 
Old 03-08-2004, 12:13 PM   #3
CorDharel
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Original Poster
Rep: Reputation: 0
I only remember these 2 thingies when I had an error in my calculator and had to set it up. What is the difference between these 2?
 
Old 03-08-2004, 11:07 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
http://math.rice.edu/~pcmi/sphere/drg_txt.html

Code:
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979

double deg2rad( double d )
{
   return (( d / 180 ) * PI );
}

double rad2deg( double r )
{
   return (( r / PI ) * 180 );
}

int main( void )
{
   printf( "cos value of x: %f\n", cos( deg2rad( 24 )));
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Very confused unkn0wnhacka Linux - General 12 07-20-2005 09:44 AM
Please help, I'm so confused sdat1333 SUSE / openSUSE 4 12-11-2004 09:23 PM
confused FrozenPenquin Linux - Newbie 26 12-09-2003 09:27 AM
C++ and very confused james.farrow Programming 5 11-28-2003 01:58 PM
so confused... KeTrueno Linux - General 1 09-28-2003 01:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration