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.
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.
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.
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.
Not sure where you would need integer values unless you're only using whole numbers.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 }
Oh. This was also posted elsewhere.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
[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
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
What i am saying what you are talking hahaha))
Your comments out of subject.
If you dont have knowledge please dont spend time meaningles.