Use const to define PI value - C++ Data Type

C++ examples for Data Type:const

Description

Use const to define PI value

Demo Code

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()//from w  w w .  java  2  s.c  om
{
   const double PI = 3.1416;
   const double DEG_TO_RAD = PI/180.0;
   double angle;
   cout << "Enter the angle (in degrees): ";
   cin  >> angle;
   cout << setiosflags(ios:: fixed) << setiosflags(ios::showpoint) << setprecision(4) << "The sine of the angle is " << sin(angle * DEG_TO_RAD) << endl;
   return 0;
}

Result


Related Tutorials