Circle Area

This is a discussion on Circle Area within the C++ Programming forums, part of the General Programming Boards category; Has any one got any idea why this doesn;t work!! Code: //Program to find circle values. #include <iostream> using namespace ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    Circle Area

    Has any one got any idea why this doesn;t work!!
    Code:
    //Program to find circle values.
    
    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
    float radius;
    float pi;
    pi = 3.14;
    float r2;
    r2 = radius*radius;
    float area;
    area = pi*r2;
    {
    
    cout << "Please input a radius so that I can work out the area of the circle!\n";
    cin >> radius;
    cout << "Thankyou! Your answer is below:\n";
    cout << "you entered:" << radius;
    cout << "/ncurrent status: not working"; 
    //the above line is a debugging tool
    }
    return 0;
    }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    radius is unintialised at first use.
    your structure needs work. how can you work out radius before asking for input etc.
    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

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    In C/C++ (okay, probably every language) the equation you supply will be applied only when you physically do so. Doing math on variables before they are inputed is sort of like photographing a baby before it is born (without a better analogy ). try this:


    Code:
    int main(){
    float radius;
    float pi = 3.14;
    float area;
    cout << "Please input a radius so that I can work out the area of the circle!\n";
    cin >> radius;
    cout << "Thankyou! Your answer is below:\n";
    cout << "you entered:" << radius;
    area = (pi*radius*radius);
    cout << "Area is : " << area;
    return 0;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    18
    Yeah my structure needs work, I fixxed it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. circle problem
    By gunghomiller in forum C++ Programming
    Replies: 10
    Last Post: 07-14-2007, 06:40 PM
  2. area of a circle
    By wise_ron in forum C Programming
    Replies: 2
    Last Post: 10-02-2006, 03:15 PM
  3. Whats wrong with my find Circle Area program?[compiles fine]
    By Golden Bunny in forum C++ Programming
    Replies: 22
    Last Post: 06-16-2002, 02:49 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 03:39 PM

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