Cant figure out very simple function problem.

I checked the search and did not find a specific answer to my problem. Hope you guys can help me on this one. I need to find the volume of a radius and I am having problems getting the return to enter the correct numbers back in main so I can send it out to another 2 functions. This is what I have so far. I know very noobish.

#include <iostream>
#include<cmath>
using namespace std;

float GetNumber (float );

long CalcNumber (long, long,long);

void DisplayNumber ();

int main ()


{
float radius, rad;

long vol,v, x;

cout<<"This prog retrieves a volume"<<endl;

rad=GetNumber (radius);
vol=CalcNumber (v);
return 0;
}

float GetNumber (float a)

{
float radius;

cout<<"What radius do you want to process?"<<endl;
cin>>radius;
return radius;

}

long CalcNumber (long a,long b, long c)

{
long v,r,pi;
pi=3.14;
v=((4/3)*pi*(3,r));
return(v);

}

void DisplayNumber (long a)

{
long volume;

cout<<"The volume is"<<volume<<endl;

}

If any of you guys can get this simple program to work right I can work off that. Once again I looked at the beginners function guide and had no luck. Fell free to change anything as long as this works right and to only use iostream and cmath, Thanks.
Last edited on
There are so many errors with my program. Let me try to make this clearer I need to get a radius with function one, Then compute its volume with function two, finally give the output with function three. 4/4*pi*(3,r) is the volume formula. R = radius in this case.
There are so many mistakes ....
I changed a little, you can try it

#include <iostream>
#include<cmath>
using namespace std;

float GetNumber (float );

long CalcNumber (long/*, long,long*/);

void DisplayNumber (long);

int main ()
{
float radius, rad;

long vol,v, x;

cout<<"This prog retrieves a volume"<<endl;

rad=GetNumber (radius);
vol=CalcNumber (rad);
DisplayNumber(vol);
return 0;
}

float GetNumber (float a)

{
float radius;

cout<<"What radius do you want to process?"<<endl;
cin>>radius;
return radius;

}

long CalcNumber (long r/*,long b, long c*/)

{
long v;//,r,pi;
long pi=3.14;
v=((4/3)*pi*(3,r)); // this is a mistake
v = ((4/3)*pi* r* r* r);
return(v);

}

void DisplayNumber (long a)

{
//long volume;

cout<<"The volume is"<<a<<endl;

}

Last edited on
Thanks so much for getting it to run but it still isnt calculating volume. The answer always comes out the same 9. The formula for volume is 4/3 * pi radius to the third power. The one I have on the program is wrongly structured. Thanks for your help anyway.
Last edited on
sorry for my mistake
the mistake i point out in the code post earlier
Think you got it man, Im gonna go over it for a little, I appreciate this alot.
--- NOTE---- using long type to hold the result of a float calculation will cause truncation errors.
Topic archived. No new replies allowed.