Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating volumes of geometric solids

Status
Not open for further replies.

Dkmaster

Technical User
Sep 10, 2008
1
0
0
US
The assignment requires to promt the user for a x and y value, and then have it output the volume of a cylinder (x as base; y as height); volume of a cone (x as base; y as height); and the volume of a sphere (use average of x and y as radius).
I have made numerous attempts to figure this out, but I keep ending up with errors and was wondering where I was going wrong. I really appreciate any guidance/help I can get.

/*
input: value of x and y
output: volume of cylinder; volume of cone; volume of sphere
*/

#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
using namespace std;

int main(void) {
double x;
double y;
double base;
double height;
double radius;
double volume_cylinder;
double volume_cone;
double volume_sphere;
double average;
cout << fixed << setprecision(11) << M_PI << endl;

//Input
cout << "Please enter a value for x ";
cin >> x;
cout << "Please enter a value for y ";
cin >> y;

// Calculations
base = x;
height = y;
base_squared = base * base;
volume_cylinder = (M_PI)*(base_squared)*(height);
volume_cone = (1.0/3.0)*(M_PI)*(base_squared)*(height);
average = ((base) + (height))/2.0
base_cubed = base * base * base
volume_sphere = (4.0/3.0)*(M_PI)*(base_cubed)

// Output
cout << fixed << setprecision(2);
cout << "The volume of the cylinder is " << volume_cylinder << endl;
cout << "The volume of the cone is " << volume_cone << endl;
cout << "The volume of the sphere is " << volume_sphere << endl;

return 0;
}
 
Well, you have two undeclared identifiers and three statements w/o terminated semicolons. It seems no need to ask anybody how to correct these obvious errors (see compiler messages).

Please, next time explain your problems explicitly.
It seems that I keep ending up with errors and was wondering where I was going wrong is a very strange help request in that case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top