Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

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

Students Click Here


calculating volumes of geometric solids

calculating volumes of geometric solids

calculating volumes of geometric solids

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

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.

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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close