fork download
  1. //Maxwell Brewer CS1A Chapter 3, P. 147, #20
  2. //
  3. /***************************************************************
  4.  *
  5.  * CALCULATE OUTPUT ANGLES
  6.  * _____________________________________________________________
  7.  *
  8.  * This program will prompt the user for an angle in radians,
  9.  * and then display the sine, cosine, and tangent of the angle.
  10.  * _____________________________________________
  11.  * INPUT
  12.  *
  13.  * radians
  14.  *
  15.  * OUTPUT
  16.  *
  17.  * sine, cosine, tangent
  18.  *
  19.  ***************************************************************/
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <cmath>
  24. #include <string>
  25.  
  26. using namespace std;
  27.  
  28. int main() {
  29.  
  30. // Initialization
  31.  
  32. const char entAngle[] = "Enter angle: \n";
  33. const char valSin[] = "The sine value is: ";
  34. const char valCos[] = "The cosine value is: ";
  35. const char valTan[] = "The tangent value is: ";
  36.  
  37. double radian, sine, cosine, tangent;
  38.  
  39. // Display input prompts
  40.  
  41. cout << entAngle;
  42. cin >> radian;
  43.  
  44. sine = sin(radian);
  45. cosine = cos(radian);
  46. tangent = tan(radian);
  47.  
  48. // Output
  49.  
  50. cout << valSin << fixed << setprecision(4) << sine << endl;
  51. cout << valCos << fixed << setprecision(4) << cosine << endl;
  52. cout << valTan << fixed << setprecision(4) << tangent << endl;
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5280KB
stdin
30
stdout
Enter angle: 
The sine value is: -0.9880
The cosine value is: 0.1543
The tangent value is: -6.4053