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
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.
Ok, wow...
For your first issue you should use a switch/case statement
1 2 3 4
In what form would you like to enter your angle
1) Radians
2) Degrees
Your choice:
Then you should do something like
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int choice = 0;
cin >> choice;
cout << "Enter the angle - ";
cin >> angle;
switch(choice) {
case 1: // They want radians
// Do your work using radians
break;
case 2: // they want degrees
// Do your work with degrees
break;
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.
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
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..