void dimensionCheck (double, char); // Function prototype - dimensions.
void holesCheck (int, char); // Function prototype - holes.
double volRec (double, double, double); // Function prototype - volume of a rectangle.
double volSph (double); // Function prototype - volume of a sphere.
double volCyl (double, double); // Function prototype - volume of a cylinder.
double volumeT (double, double, double, int, double, int, double, double); // Function prototype - final volume.
const double PI = 3.14159; // Global constant pi = 3.14...
int main ()
{
double length, width, height; // Rectangle dimension for block.
double radCyl, radSph, heightCyl; // Circular member dimensions.
double volume; // Final Volume.
int numSph, numCyl; // Number of cylinders & spheres.
cout << "Input the height, length, and width of the cheese block: ";
cin >> height >> length >> width;
cout << "How many cylindrical holes are present?";
cin >> numCyl;
cout << "Enter the radius and height of the cylidrical holes in centimeters: ";
cin >> radCyl, heightCyl;
cout << "The total volume of cheese present is " << volume
<< " cubic centimeters." << endl;
return 0;
}
// *********** FUNCTION DEFINITIONS ****************
// Make sure all dimension are valid - greater than zero.
void dimensionCheck (double &dimension, char which[2])
{
if (which == "ht")
{
if (dimension <= 0)
{
cout << "The height of the cheese must be greater than zero."
<< "Please re-enter the height of the cheese: ";
cin >> dimension;
dimensionCheck(dimension, 'ht');
}
}else if(which == "lg")
{
if (dimension <= 0)
{
cout << "The length of the cheese must be greater than zero."
<< "Please re-enter the length of the cheese: ";
cin >> dimension;
dimensionCheck(dimension, 'lg');
}
}else if(which == "wd")
{
if (dimension <= 0)
{
cout << "The width of the cheese must be greater than zero."
<< "Please re-enter the width of the cheese: ";
cin >> dimension;
dimensionCheck(dimension, 'wd');
}
}else if(which == "rs")
{
if (dimension <= 0)
{
cout << "The radius of the sphere(s) hole must be greater than zero."
<< "Please re-enter the radius of the sphere(s): ";
cin >> dimension;
dimensionCheck(dimension, 'rs');
}
}else if(which == "rc")
{
if (dimension <= 0)
{
cout << "The radius of the cylinder(s) hole must be greater than zero."
<< "Please re-enter the radius of the cylinder(s): ";
cin >> dimension;
dimensionCheck(dimension, 'rc');
}
}else if(which == "hc")
{
if (dimension <= 0)
{
cout << "The height of the cylinder(s) be greater than zero."
<< "Please re-enter the height of the cylinder(s): ";
cin >> dimension;
dimensionCheck(dimension, 'hc');
}
}
}
// Make sure number of holes (cyl. & spheres) are valid - greater than zero.
void holesCheck (int &howmany, char which[2])
{
if (which == "sph")
{
if (howmany <= 0)
{
cout << "The number of spheres must be greater than zero."
<< "Please enter the number of spherical holes: ";
cin >> howmany;
holesCheck(howmany, 'cyl');
}
}else if (which == "cyl")
{
if (howmany <= 0)
{
cout << "The number of cylinders must be greater than zero."
<< "Please enter the number of spherical holes: ";
cin >> howmany;
holesCheck(howmany, 'cyl');
}
}
}
// Calculates the volume of the rectangle.
double volRec (double hgt, double lgt, double wdt)
{
double R; // Volume of a rectangle.
R = (hgt*lgt*wdt);
return R;
}
// Calculates the volume of the sphere(s).
double volSph (double rad)
{
double S; // Volume of a sphere.
S = ((4.0/3.0)*PI*rad*rad*rad);
return S;
}
// Calculates the volume of the cylinder(s).
double volCyl (double rad, double hgt)
{
double C; // Volume of a cylinder.
C = (PI*rad*rad*hgt);
return C;
}
// Calculates the final volume of the block of cheese.
double volumeT (double hgt, double lgt, double wdt, int sph, double spR, int cyl, double cyR, double cyH)
{
double T; // Total volume (final volume);
T = (volRec(hgt,lgt,wdt) - ((sph * volSph(spR)) - (cyl*volCyl(cyR,cyH))));
return T;
}
1) Prototype for dimensionCheck is void dimensionCheck (double, char);. You are calling it as dimensionCheck (height, 'ht');: 'ht' is not a char (well, actually it is, but is is not that you would expect). And finally function definition is void dimensionCheck (double &dimension, charwhich[2]) which equals to void dimensionCheck (double &dimension, char* which)
2) Exact problem with holesCheck
3) cin >> radCyl, heightCyl; should be cin >> radCyl >> heightCyl;
4) (which == "ht"): you cannot compare c-strings like that