write a program that asks the user for angle ,entered in radians.The program should then display the sine ,cosine and the tangent of the angle.(Use the functions provided in the C++ math library).The outputs should be display in fixed-point notation,rounded to four decimal places of precision and formatted.
how to modify this program to accept angle in degrees,instead of radians
write a program

Why don't you write the program? Then we can help you from there.

Post the code and compiler output if you have problems.

Don't forget to use code tags the <> button on the right

Also, look in the reference section, top left of this page, for things you don't understand

And Google, your best friend.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
const double PI = 3.14259;

double angle;
double radian ;
double degree ;
double sin1;
double cos1;
double tan1;
double rad1;
cout << fixed << setprecision (4);
cout << " Please enter the angle in degree = " << "\n" << "or in radian = " ;
cin >> degree << radian;
rad1 = degree * PI / 180;

switch (angle)
case"degree" :if (degree >= 0 && degree <=360)
sin1 = sin(rad1);
cos1 = cos(rad1);
tan1 = tan(rad1);

case"radian": if (radian >= 0 && radian <= 2*PI)
sin1 = sin(radian);
cos1 = cos(radian);
tan1 = tan(radian);

return 0;
Can somebody tell me what wrong with my answer?
cin >> degree << radian;

The usage is wrong here. You ask for one input, you attempt to get two. Only ">>" can be used with cin.

case"degree" :

You're switching on angle, therefore your case must be the same type as angle. "degree" and "radian" are not of type double. It wouldn't really make sense to switch on anything but an integral or boolean type.

I would suggest that you ask the user whether they wish to enter the angle in degrees or radians before you ask for the angle. Keep track of the answer, and act accordingly.
Last edited on
Ok, wow...
For your first issue you should use a switch/case statement
In what form would you like to enter your angle
1) Radians
2) Degrees
Your choice: 

Then you should do something like
int choice = 0;
cin >> choice;
cout << "Enter the angle - ";
cin >> angle;
switch(choice) {
        case 1: // They want radians
                // Do your work using radians
        case 2: // they want degrees
                // Do your work with degrees
        default: // They entered something else
                // Send some error

This way you only need one variable to hold either type of angle, and you would just process the variable differently in each case statement.

Hope I helped :)
Or just do the work in radians, and convert the answer to degrees if they want degrees for some odd reason. Better than writing the same work twice imo
That is a much better solution :)

But the switch/case is still the way to go.
Last edited on
The arguments of the switch ( ... ) in C++ math library is a (int ) and (char), and your solutions is assigned an (double), and 'case' this a string (this wrong), the test case this is {1,2,3,..}.., and not included the 'default:break;' for this case no apply..


Topic archived. No new replies allowed.