Need help using a function to convert

For this program I am trying to take the output of the function and convert it to degrees to display both radians and degrees. I have created a function to solve radians to degrees, but do not know how to implement it to my cases. Line 38- 40 is where i have attempted the conversion.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define    _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

double rad2deg(int x);

int main()
{

	char function;
	double val;

	cout << "This calculator requires you to enter a funtion and a number" << endl;
	cout << "The functions are as follows: " << endl;
	cout << "S - sine " << endl;
	cout << "C - cosine " << endl;
	cout << "T - tangent " << endl;
	cout << "R - square root " << endl;
	cout << "N - natural log " << endl;
	cout << "X - exit the program " << endl;

	cout << endl;

	cout << "Please enter a function and a value: " << endl;
	cin >> function >> val;

	while (toupper(function) != 'X')
	{
		double radians;

		switch (function)
		{
		case 'S':
			radians = sin(val);
			cout << "The sine of your number in radians is " << sin(val) << endl;
			cout << "The sine of your number in degrees is " << rad2deg(radians) << endl;
			break;
		case 'C':
			cout << "The cosine of your number is " << cos(val) << endl;
			break;
		case 'T':
			cout << "The tangent of your number is " << tan(val) << endl;
			break;
		case 'R':
			cout << "The square root of your number is " << sqrt(val) << endl;
			break;
		case 'N':
			cout << "The natural log of your number is " << log(val) << endl;
			break;
		case 'X':
			break;
		}

		cout << "Please enter a function and a value: " << endl;
		cin >> function >> val;

	}

	cout << "Thanks for using the calculator" << endl;

	return 0;
}
double rad2deg(int x)
{
	double degrees;
	double radians;

	degrees = radians * 180 / M_PI;
	return degrees;
}
Last edited on
Dont put double radians; in the while, it will define it every loop.

Topic archived. No new replies allowed.