Programming PI

This is a discussion on Programming PI within the C++ Programming forums, part of the General Programming Boards category; VisualC++6.0 This is for a Calculate the area of a circle given the diameter. Ok this is what I have ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    Wink Programming PI

    VisualC++6.0
    This is for a Calculate the area of a circle given the diameter.

    Ok this is what I have so far;
    #include<math.h>
    voidmain(void)
    {
    pie,diameter,areais,sqrt(2);

    cout<<"Enter Pie ";
    cin>>Pie;
    cout<< "Enter Diameter ";
    cin>>diameter;
    cout<< "Enter Area Is ";
    cin>>areais;
    cout<< "EnterSquare(2) ";
    cin>>sqrt(2)

    pie *4Sqrt(2)


    Do I have everything so far.

  2. #2
    Unregistered
    Guest

    Angry

    No.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    To calculate the area, you only need input the diameter.

    You've got cout and cin sorted, but you need to work on declarations and assignments
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    when i was at school PI * r*r gives the area of a circle. Given that r= 0.5*d this problem should be easy.

    Code:
    #include<iostream>
    
    using namespace std;
    
    int main() // not void main() cos thats illegal
    {
    const double PI= 3.14159 // you might have to check that value
    cout<<"Enter diameter";
    double diameter,radius;
    cin>>diameter;
    radius=diameter*0.5;
    double area=radius*radius*PI;
    cout<<endl<<"Area of circle is "<<area<<" units squared"<<endl;
    return 0;
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

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