how to convert degrees into radians in a c++ program

I had to create a program which calculates the shortest distance between to coordinates on earth's surface that the user inputs. The formula contains a lot of sin and cos functions which only accept radians and my professor wants the user to input the degrees and he wants me to convert the degrees the user inputs to radians from the source code. How can i do this without multiplying every degree the user inputs by (pi/180) in the formula??

here is what my source code looks like:

#include<iostream>
#include<cstdlib>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
cout <<"Enter the latitude of point 1: ";
double a;
cin >>a;

cout <<"Enter the longtitude of point 1: ";
double b;
cin >>b;

cout <<"Enter the latitude of point 2: ";
double e;
cin >>e;

cout <<"Enter the longitude of point 2: ";
double f;
cin >>f;

double r=3959.87;
double q=acos(1.0*sin(a)*sin(e)+cos(a)*cos(e)*cos(b-f));//this is where the degrees have to be converted to radians
double d=r*q;

cout << fixed << setprecision(2);

cout <<"The distance between: (" <<a <<", " <<b <<") and (" <<e <<", " <<f <<") is " <<d <<endl;

system("PAUSE");
return 0;
}

thanks!!
1) Multiply all values by Pi/180

2) Get a library which takes degree arguments

3) Create a function (or class) which will do conversion for you:
1
2
3
4
5
6
7
8
9
10
11
double get_degrees()
{
    const double halfC = M_PI / 180;
    double input;
    std::cin >> input;
    retun input * halfC;
}

//...
cout <<"Enter the latitude of point 1: ";
double a = get_degrees();
There are 360 degrees in a circle. And that 360 degrees is equivalent to 2*pi radians.

So, converting and angle x degrees to radians is 2*pi * (x / 360).
hello,

Converting from degrees to radians

Decrees are converted to radians in the following way:

radians = ( degrees * pi ) / 180 ;

Converting from radians to degrees

Radians are converted to degrees in the following way:

degrees=( radians * 180 ) / pi ;

see this too http://www.mathinary.com/degrees_radians.jsp
Topic archived. No new replies allowed.