Pi

This is a discussion on Pi within the C++ Programming forums, part of the General Programming Boards category; Is there anyway I can insert Pi into an equation using C ++ without having to write out the whole ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    Pi

    Is there anyway I can insert Pi into an equation using C ++ without having to write out the whole number?

  2. #2
    Unregistered
    Guest

    Lightbulb

    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

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    16
    Thank you. It works.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    or you could just say

    const double PI = 3.14159265359

    Is that that difficult?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pi - Hm, somethign is not right here.
    By MadnessRed in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2008, 01:07 PM
  2. PI Equation in C
    By wallysworld in forum C Programming
    Replies: 13
    Last Post: 10-23-2006, 08:12 PM
  3. Pi Calculation
    By EvilGuru in forum C Programming
    Replies: 2
    Last Post: 05-02-2005, 04:25 AM
  4. Pi and the standard library
    By FOOTOO in forum C Programming
    Replies: 7
    Last Post: 04-15-2005, 11:23 AM
  5. C for PI
    By Lynux-Penguin in forum C Programming
    Replies: 13
    Last Post: 04-28-2002, 07:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21