Chapter 3 – #22: Angle Calculator – Tony Gaddis – Starting Out With C++

>_ Problem

Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision.

>_ Solution

#include <iostream>
#include <iomanip>  // setprecision()
#include <cmath>    // sin(), tan(), and cos()

using namespace std;

int main()
    // Variables
    double angle;

    // Ask the user for an angle in radians
    cout << "\nWhat is an angle in radians? ";
    cin >> angle;

    // Display the sine, cosine, and tangent of the angle
    cout << setprecision(4) << fixed;
    cout << "Angle in radians  = " << angle << endl;
    cout << "Sine of the angle = " << sin(angle) << endl;
    cout << "Cosine of angle   = " << cos(angle) << endl;
    cout << "Tangent of angle  = " << tan(angle) << endl;
    cout << endl;

    // Terminate Program
    return 0;

>_Get The Book!

Tony Gaddis’ book “Starting Out with C++ from Control Structures to Objects”: 8th and 9th editions.

>_ Video Walk Through

This video includes a step by step process of how I solve programming challenge #22.

>_That’s it!

Thank you for taking interest what I do! I hope it was helpful for you as much as it helped me along my journey in learning to code!

>_ Also Check Out:

Category: Starting Out With C++ | Chapter 3 | Programming Challenge Solutions

Leave a Reply