When asked to create a program to find the volume of any con

When asked to create a program to find the volume of any cone, given its radius and height, a programmer created this program to implement the formula V=1/3 r^2 h. Compute the following to correct the program: a. Provide the correct parameters for the ComputeVolume function b. Write the call for the function in int main c. Define the ComputeVolume function d. Initialize any other necessary variables

#include using namespace std;

void ComputeVolume ( ); //parameters

int main() { double radius, height, answer; cout << \"Input the radius and height of the cone.\" << endl; cin >> radius >> height; cout<<\" Radius : \"<< radius; cout<< \" Height : \" << height; // Call the function cout<< \" Volume :\"< < answer; return 0; } void ComputeVolume ( ){ //parameters //define function return; }

Solution

#include <stdio.h>
#define PIE 3.14
float ComputeVolume(float r, float h, float ans, float r2);
int main() {

float radius , height , ans, r2;

printf(\"Radius: \");

scanf(\"%g\", &radius);

printf(\"Height: \");

scanf(\"%g\", &height);

ans = ComputeVolume(radius , height , ans, r2);

printf(\"Volume: %g\ \", ans);

return 0;

}
float ComputeVolume(float r, float h, float ans, float r2)

{

r2 = r*r;

ans = (1/3)*PIE*r2*h;

return ans;

}

When asked to create a program to find the volume of any cone, given its radius and height, a programmer created this program to implement the formula V=1/3 r^2

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site