Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//Cone Volume Calculator Program #include <iostream> using namespace std; int ma

ID: 672709 • Letter: #

Question

//Cone Volume Calculator Program

#include <iostream>
using namespace std;

int main( )
{
    //Declare variables and constants
    double coneRadius = 0.0;
    double coneHeight = 0.0;
    const double PI = 3.1415;
    double coneVolume = 0.0;

    //Prompt the user for inputs
    cout << "Enter the radius of the cone: ";
    cin >> coneRadius;
    cout << "Enter the height of the cone: ";
    cin >> coneHeight;

    //Do the calculation
    coneVolume = 0.3333 * PI * coneRadius * coneRadius * coneHeight;

    //Display the result
    cout << "The volume of your cone is: " << coneVolume << endl;

    system("pause");
    return 0;
} //end of main


2) we want the program to do the same thing, but with not one main() function, but instead one main() function PLUS one user defined function called computeConeVolume that contains the calculation. In other words, remove the one line calculation, replace it with a function call, then write and add the function below main with the calculation, surrounded any other syntax you need to complete it. Determine how to do all that. Note that recent sample programs can be of a real help to you here, in addition to the book, of course.

Notes:
    * The function should contain local variables and a constant declared and must have the calculation, it may not do anything else such as input or output.
    * You may not declare "global" variables anywhere. No variables above or outside of main() and the function are allowed.
    * A value-returning function should be used because it's a little simpler to understand, but you can employ a void function if you desire.
    * Be sure to have a function prototype at the top of the code, then main, then your function.
    * You may test your code by copying and running the original program ( with only main() ), then comparing the results to your new program.
    * Test with "real" numbers including decimals, like 3.4 and 5.8
        * Don't use 1 anywhere - that number is so simple it can give the right answer sometimes if the program is wrong.

Explanation / Answer

#include <iostream.h>
using namespace std;
void computeConeVolume();

int main( )
{

computeConeVolume();
system("pause");

return 0;
} //end of main

void computeConeVolume()
{
double coneRadius = 0.0;
double coneHeight = 0.0;
const double PI = 3.1415;
double coneVolume = 0.0;

//Prompt the user for inputs
cout << "Enter the radius of the cone: ";
cin >> coneRadius;
cout << "Enter the height of the cone: ";
cin >> coneHeight;

//Do the calculation
coneVolume = 0.3333 * PI * coneRadius * coneRadius * coneHeight;

//Display the result
cout << "The volume of your cone is: " << coneVolume << endl;

}