fork download
  1. //Diego Martinez CSC5 Chapter 3, P. 147,#20
  2.  
  3. /*******************************************************************************
  4. * Working Angle Calculator
  5. * ______________________________________________________________________________
  6. * This program that helps users compute the sine, cosine, and tangent of an
  7. * angle given in radians.
  8. *
  9. * Computation is based on the Formula:
  10. * sine = std::sin(angle)
  11. * cosine = std::cos(angle)
  12. * tangent = std::tan(angle)
  13. *_______________________________________________________________________________
  14. * INPUT
  15. * The program prompts the user to enter an angle in radians
  16. *
  17. * OUTPUT
  18. * Sine of the angle (sin(θ))
  19. * Cosine of the angle (cos(θ))
  20. * Tangent of the angle (tan(θ))
  21. *
  22. *******************************************************************************/
  23. #include <iostream>
  24. #include <iomanip> // For std::fixed and std::setprecision
  25. #include <cmath> // For sin, cos, tan
  26.  
  27. int main() {
  28. double angle;
  29.  
  30. // Ask the user to enter an angle in radians
  31. std::cout << "Enter an angle in radians: ";
  32. std::cin >> angle;
  33.  
  34. // Compute sine, cosine, and tangent
  35. double sine = std::sin(angle);
  36. double cosine = std::cos(angle);
  37. double tangent = std::tan(angle);
  38.  
  39. // Display the results in fixed-point notation with 4 decimal places
  40. std::cout << std::fixed << std::setprecision(4);
  41. std::cout << "Sine: " << sine << "\n";
  42. std::cout << "Cosine: " << cosine << "\n";
  43. std::cout << "Tangent: " << tangent << "\n";
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter an angle in radians: Sine: 0.0000
Cosine: 1.0000
Tangent: 0.0000