×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# calculating volumes of geometric solids

## calculating volumes of geometric solids

(OP)
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 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;
}

### RE: calculating volumes of geometric solids

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).

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.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!