fork download
  1. //Faith Tjia CSC5 Chapter 3, P. 147, #20
  2. //
  3. /*****************************************************************************
  4.  * ANGLE CALCULATOR
  5.  * ___________________________________________________________________________
  6.  * This program will ask the user to enter an angle (in radians), it will then
  7.  * calculate and display the sine, cosine, and tangent of the angle.
  8.  *
  9.  * FUNCTIONS USED
  10.  * sin(x), cos(x), tan(x)
  11.  * ___________________________________________________________________________
  12.  * INPUT
  13.  * angle: The angle given by the user
  14.  *
  15.  * OUTPUT
  16.  * sinA
  17.  * cosA
  18.  * tanA
  19.  *
  20.  * **************************************************************************/
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <cmath>
  24. using namespace std;
  25.  
  26. int main() {
  27. double angle; //INPUT - The angle given by the user
  28. double sinA; //OUTPUT - The sine of the angle
  29. double cosA; //OUTPUT - The cosine of the angle
  30. double tanA; //OUTPUt - The tangent of the angle
  31.  
  32. //
  33. // Initialize Program Variables
  34. cout << "Enter an angle in the form of radians: ";
  35. cin >> angle;
  36. cout << angle << endl;
  37. //
  38. // Compute Sine, Cosine, and Tangent
  39. double sinA = sin(angle);
  40. double cosA = cos(angle);
  41. double tanA = tan(angle);
  42.  
  43. //
  44. // Display Sine, Cosine, and Tangent of the Angle
  45. cout << "The sine of the angle is " << setprecision(4) << fixed << sinA <<
  46. endl;
  47. cout << "The cosine of the angle is " << setprecision(4) << fixed << cosA
  48. << endl;
  49. cout << "The tangent of the angle is " << setprecision(4) << fixed << tanA
  50. << endl;
  51. return 0;
  52. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Enter an angle in the form of radians: 6.95266e-310
The sine of the angle is 0.0000
The cosine of the angle is 1.0000
The tangent of the angle is 0.0000