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.
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
usingnamespace 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;
}