This program runs all of the functions for each condition, when it should only run one function for each condition. Why? i am supposed to Write functions that compute the volume and surface area of a sphere, circular cylinder, and a circular cone: I can't figure out if it is the if statements that are messing up,or the functions themselves. An ideal output for this program would be as follows:
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: 1 Select a Computation (1) volume (2) surface area: 1 Enter radius of sphere: 5.5 Volume of sphere is 696.91
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: 1 Select a Computation (1) volume (2) surface area: 2 Enter radius of sphere: 5.5 Surface area of sphere is 380.133
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: 2 Select a Computation (1) volume (2) surface area: 1 Enter radius of cylinder: 5.5 Enter height of cylinder: 4.2 Volume of cylinder is 399.139
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: 2 Select a Computation (1) volume (2) surface area: 2 Enter radius of cylinder: 5.5 Enter height of cylinder: 4.2 Surface area of cylinder is 335.208
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: 3 Select a Computation (1) volume (2) surface area: 1 Enter radius of cone: 5.5 Enter height of cone: 4.2 Volume of cone is 133.046
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: 3 Select a Computation (1) volume (2) surface area: 2 Enter radius of cone: 5.5 Enter height of cone: 4.2 Surface area of cone is 214.607
Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: q
Good bye!
#include <iostream>
#include <math.h>
using namespace std;
double sphere_volume(double radius);
double sphere_surface_area(double radius);
double cylinder_volume(double radius, double height);
double cylinder_surface_area(double radius, double height);
double cone_volume(double radius, double height);
double cone_surface_area(double radius, double height);
int main()
{
double entHeight;
double entRadius;
char shapeCall;
char compCall;
cout << "Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: ";
cin >> shapeCall;
cout << "Select a Computation (1) volume (2) surface area: ";
cin >> compCall;
if ( shapeCall == 1 )
{
if ( compCall == 1)
cout << "Enter Radius: ";
cin >> entRadius;
cout << sphere_volume (entRadius) << endl;
}
if ( shapeCall == 1 )
{
if ( compCall == 2)
cout << "Enter Radius: ";
cin >> entRadius;
cout << sphere_surface_area (entRadius) << endl;
}
if ( shapeCall == 2 )
{
if ( compCall == 1)
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cylinder_volume (entRadius, entHeight) << endl;
}
if (shapeCall == 2 )
{
if ( compCall == 2)
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cylinder_surface_area (entRadius, entHeight) << endl;
}
if (shapeCall == 3 )
{
if ( compCall == 1)
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cone_volume (entRadius, entHeight) << endl;
}
if (shapeCall == )
{
if ( compCall == 2)
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cone_surface_area (entRadius, entHeight) << endl;
}
return 0;
}
double sphere_volume(double radius)
{
double sphereVolume;
sphereVolume = 3.14 * pow(radius, 3) * 4/3;
return sphereVolume;
}
double sphere_surface_area(double radius)
{
double sphereSurfArea = 4 * 3.14 * pow( radius, 2 );
return sphereSurfArea;
}
double cylinder_volume(double radius, double height)
{
double cylinderVolume = 3.14 * pow (radius, 2) * height;
return cylinderVolume;
}
double cylinder_surface_area(double radius, double height)
{
double cylinderSurfArea = 2 * 3.14 * pow (radius, 2) + 2 * 3.14 * radius * height;
return cylinderSurfArea;
}
double cone_volume(double radius, double height)
{
double coneVolume;
coneVolume = (1/3) * 3.14 * pow (radius, 2) * height;
return coneVolume;
}
double cone_surface_area(double radius, double height)
{
double coneSurfArea = 3.14 * pow (radius, 2) + 3.14 * sqrt(pow (radius, 2) + pow (height, 2));
return coneSurfArea;
}