spheres volume calculator help

Hi everyone, I'm currently in the process of making a program that prompts the user for two radius of two separate spheres then it calculates the sum of the two radius's. Then it takes the final sum and calculates the volume of a sphere from that sum ((4/3)pie(r)^3). I'm having trouble getting the correct calculations just using int main(). So i've been trying to use the void function to help me out but I am getting errors. I will post what I have so far and if anyone can help me in the right direction it will be much appreciated.

Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cmath>
#include <iostream>

using namespace std;

void sum (double, double);

int main()
{
    double r1,r2;
    cout<<"Enter in two radii: ";
    cin >>r1>>r2;
    
    sum(r1,r2);
    volume;
    


    system("PAUSE");
    return EXIT_SUCCESS;
}

void sum(double r1, double r2)
{
     double total;
     total = r1 + r2;
     cout<<total;
     
     }

void volume (double pie, double constant, double r)
{
     double total;
     
     constant=4/3;
     r= sum;
     pie=3.14159;
     
     total= constant*pie*r*r*r;
     
     cout<<total;
     }
     
     
closed account (o3hC5Di1)
Hi there,

What kind of errors are you getting? Compilation errors or runtime errors? Also, could you please copy the errors you are getting into your post?

Thanks,
NwN
1) you are not calling your volume function
2) Why do you have 3 arguments here?
Do not use argument list to declare additional variables to use.
3) 4/3 = 1.

do something like:

1
2
3
4
5
6
7
void volume(double radius)
{
    const double coeff = 4.0/3.0; //sic!
    double vol = coeff * M_PI * radius * radius* radius;
 
    std::cout << vol;
}
Last edited on
MiiNiPaa, you are right I had too many arguments. Looking at the code you wrote made it much more simple. I was trying to complicate things by parting out the equation. I forgot to make it 4.0/3.0 instead of 4/3.

Thanks a lot for your help.
Topic archived. No new replies allowed.