Answer to Question #330874 in C++ for florence

Question #330874

Write a complete program that prompts the user for the radius of a sphere, and calculates and

prints the volume of that sphere. Use a function sphereVolume that returns the result of the

following expression: (4/3) × π × r3 which is equivalent to

( 4.0 / 3.0 ) * 3.14159 * pow( radius, 3 ) in C++ code.

Sample output

Enter the length of the radius of your sphere: 2


1
Expert's answer
2022-04-19T08:07:09-0400
#include <iostream>
#include <cmath>
using namespace std;


double sphereVolume(double radius) {
    double volume;
    volume = (4.0/3.0) * 3.14159 * pow(radius, 3);
    return volume;
}


int main() {
    double radius, volume;


    cout << "Enter the length of the radius of you spger: ";
    cin >> radius;
    volume = sphereVolume(radius);
    cout << "The volume of your sphere is " << volume << endl;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS