Thread: Area and volume of cylinder

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Area and volume of cylinder

    Hello friends,
    I would like to calculate area and volume of cylinder but radious and height should be integer, float and double. How can i do?
    May you help me?
    Thank you.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Do you know the formulae to calculate area and volume of a cylinder mathematically?

    All you need to do then is convert that formula into relevant code, using whatever variable types are required. Since there is a factor of pi in both calculations, and pi is not an integral value, I assume the area and volume do not need to be integral values.

    Multiplying an integer value by a floating point (float or double) value always promotes the integer to the floating point type before performing the multiplication, and the result is also of that floating point type.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Location
    Morden, UK
    Posts
    128
    The volume is:

    [code]
    3.142 x (radius x radius) x height
    [code]

    What about a couple of floats for the radius and height values.

    Code:
    #include <iostream>
    
    int main ()
    {
        float radius;
        float height;
        
        std::cout << "Enter radius: ";
        std::cin >> radius;
        std::cout << "Enter height: ";
        std::cin >> height;
        
        //now you have radius and height stored, output the result here using your calculation
    }
    Not sure where you would need integer values unless you're only using whole numbers.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Oh. This was also posted elsewhere.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by samwillc View Post
    The volume is:
    3.142 x (radius x radius) x height
    Note that pi is an irrational number (i.e. it cannot be computed exactly as a ratio of two integers). 3.142 is only an approximation. A more accurate approximation may be needed, depending on what precision of results are required.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    [QUOTE=grumpy;1160511]Note that pi is an irrational number (i.e. it cannot be computed exactly as a ratio of two integers). 3.142 is only an approximation. A more accurate approximation may be needed, depending on what precision of results are required.[/QUOTE

    My friends radious and height will enter from keyboard. I think i am using lots of codes. Thers should be easy way. Input number can be integer, float or double.

    Also in your code you did height and radious as a float. What if i enter as integer program how should understand.

    Thanks

    Laserlight, you are looking more than me from my questions you jelious me

  7. #7
    Registered User
    Join Date
    Jun 2012
    Location
    Morden, UK
    Posts
    128
    If you use an integer, if your friend types in 3.57 for the radius, it will be saved as 3, which will give you an inaccurate result.

    I used PI as 3.142 as an approximation as grumpy said. Press the symbol for this on your calculator and see what the real number is.

    As far as 'easy way' goes, there is one, and the answer is within this thread

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by samwillc View Post
    I used PI as 3.142 as an approximation as grumpy said. Press the symbol for this on your calculator and see what the real number is.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Registered User
    Join Date
    Jun 2012
    Location
    Morden, UK
    Posts
    128
    Quote Originally Posted by grumpy View Post
    I use my calculator all the time!

  10. #10
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    What i am saying what you are talking hahaha))
    Your comments out of subject.
    If you dont have knowledge please dont spend time meaningles.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-15-2013, 03:31 AM
  2. USB Problem : Volume to Volume copy by sector
    By anuj7anuj in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2011, 08:47 AM
  3. OpenGL: Draw cylinder yourself
    By iMPR3SSiON in forum Game Programming
    Replies: 5
    Last Post: 01-11-2011, 09:55 PM
  4. Replies: 44
    Last Post: 03-19-2010, 04:06 PM
  5. Raw volume access (to a usb volume)
    By _izua_ in forum Windows Programming
    Replies: 9
    Last Post: 11-02-2009, 07:05 AM