Question: Write a program that invokes a function to calculate a cylinder's volume whose radius and height is given by a user. Note: no credit is

Write a program that invokes a function to calculate a cylinder's volume whose radius and height is given by a user. Note: no credit is given if not using a function call to fulfill this assignment (Refer to Programmer Defined Function .cpp file posted on Moodle).

Your program should call a function named volume which takes in radius and height as two parameters, then return the calculated volume using the formula below:

cylinder volume = Pi * radius^2 * height (ignore unit for simplification)

Define Pi as a double constant with value 3.14159 (refer to textbook page 223).

For example, if a user types in 3 for radius and 5 for height, your program should pass 3 and 5 to the function "volume". Then function "volume" will calculate and return the result of 3.14159 * 32 * 5, i.e. 141.37155. Please keep at least two decimal digits for precision. So 141 or 141.3 are not accepted while 141.37 is accepted. Your program should print out this result for the user.

After printing out the result, ask the user if she wants to run the program again. If the user answers yes, run it again, otherwise exit. Your program can accept a user response of Y for yes, and assume anything else means no.

Please name your submitted .cpp file with the following format: "HW03_CylinderVolume_YOUR NAME.cpp". For example, "HW03_CylinderVolume_John Smith.cpp". Only .cpp file is accepted.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!