Is there anyway I can insert Pi into an equation using C ++ without having to write out the whole number?
Is there anyway I can insert Pi into an equation using C ++ without having to write out the whole number?
does this help?????
/**************************
to use this program please
leave my comments box
untouched, otherwise use as
you will.
this program displays the
use (and definition) of PI
written by
MICHAEL MCGUIRE 20/09/01
**************************/
#include<iostream.h>
#include<math.h>
void main()
{
float length;
float width;
float diameter;
float area;
float num;
double pi = atan(1) * 4;//define pi
cout<<"AREA CALCULATOR\n\n\n\n";//title
cout<<"select a shape from below\n";
cout<<"1:- rectangle\n";
cout<<"2:- circle\n";
cout<<"3:- triangle\n";
cout<<"\nenter a number and then press enter\n";
cin>>num;
if (num == 1){//if 1 is entered do this
cout<<"\nenter the length of the rectangle : ";
cin>>length;
cout<<"\nenter the width of the rectangle : ";
cin>>width;
area=(length * width);
cout<<"\n\nthe area of your rectangle is :"<<area;
cout<<endl;
}
else if (num == 2){//or if 2 is entered do this
cout<<"\nenter the diameter of the circle : ";
cin>>diameter;
area=(pi * diameter);////
cout<<"\n\nthe area of your circle is : "<<area;
cout<<endl;
}
else if (num == 3){//or if 3 is entered do this
cout<<"\nenter the length of the triangle : ";
cin>>length;
cout<<"\nenter the width of the triangle : ";
cin>>width;
area=(length*width)/2;
cout<<"\n\nthe area of your triangle is : "<<area;
cout<<endl;
}
//if none of the above are enterd do this (error statement!!!)
else cout<<" ********** WRONG NUMBER ENTERED ***********\n\n\n\n";
//maybe add a loop statement to the program
//in case the user isn't finished
}//end of program
Thank you. It works.
or you could just say
const double PI = 3.14159265359
Is that that difficult?
-Govtcheez
[email protected]