View Full Version : functions
Dorian Mayorquin
January 4th, 2011, 08:48 PM
Hi guys, i'm having trouble with this code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double a = 8;
cout << "This is tangent of 8\n"<< tan(a) <<endl;
return 0;
}
it keeps giving me the wrong result it says that is: -6.79971
Arndt
January 4th, 2011, 09:06 PM
Hi guys, i'm having trouble with this code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double a = 8;
cout << "This is tangent of 8\n"<< tan(a) <<endl;
return 0;
}
it keeps giving me the wrong result it says that is: -6.79971
It's probably correct. The argument is in radians, not degrees.
Lootbox
January 5th, 2011, 12:13 AM
Arndt is correct. A good place to look these types of things up is at http://www.cplusplus.com/reference/. The entry for the tan function (here (http://www.cplusplus.com/reference/clibrary/cmath/tan/)) explains what type of parameter it expects.
WRDN
January 5th, 2011, 12:17 AM
tan(8.0) is equal to -6.79971, as the parameter provided is radians, as Arndt noted.
If you want to convert between them:
Radians = Degrees * (PI/180)
Degrees = Radians * (180/PI)
PI = 3.14159265
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.