Public Group

# Problem with C++ math

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

## Recommended Posts

I have been programming with Java for a while and never ran into any problems using its math functions, but when I switched over to C++ I cant get any of them to work. Can anyone tell me what to include and how to use cosine , tangent , sine , atan ,etc.

##### Share on other sites
First of all, you need to #include <cmath>

The functions are pretty straight forward. I googled this. It seems like a pretty good reference.

##### Share on other sites
Thanks for the fast reply that helped alot.

##### Share on other sites
#include <cmath>
using namespace std;

##### Share on other sites
Bah real men write their own. (which i still havn't fixed)
#include <iostream>#include <math.h>#define PIENOTCAKE 3.1415926535897932384626433832795unsigned int factorial(unsigned int number){	unsigned int holder = number;	unsigned int i = number;	while (i>0)	{		if (i == 1)		{			break;		}		i--;		holder *=i;	}	return holder;}long double getsigma(long double n, long double x){	//long double retvalue;	//retvalue = ((pow(-1, n))/factorial(2*n + 1))*pow(x,2*n + 1);	return ((pow(-1, n))/factorial(2*n + 1))*pow(x,2*n + 1);}int main(int argc, char *argv[]){	int i = 1;	long double totaler;		totaler = getsigma(0,PIENOTCAKE/3);		while (i<15)	{		totaler += getsigma(i,PIENOTCAKE/3);		i++;	}	std::cout << "Sine of PI/3: "<<totaler<<std::endl;	system("pause");	return 0;}

Cmath

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 13
• 46