# Thread: need help, Volume of cone is always 0??

1. ## need help, Volume of cone is always 0??

hello there
am trying to compute the volume of a cone using a function but it always gives 0, why???
i still an amateur so excuse me

Code:
```# include <stdio.h>
# define PIE 3.14
float ComputeVolume ( float r, float h, float ans , float r2 );
int main () {
float radius=0 , height=0 , ans, r2;
printf (" Height : ");
scanf ("%f", & height );
ans = ComputeVolume (radius , height , ans , r2 );
printf (" Volume : %f\n", ans );
system("PAUSE");
return 0;
}
float ComputeVolume ( float r, float h, float ans , float r2)
{
r2 = r*r;
ans = (1/3)* PIE *r2*h;
return ans ;
}```
any help?!!!

2. > ans = (1/3)* PIE *r2*h;
1/3 in integer maths is zero.

Make the expression a double.

SourceForge.net: Indentation - cpwiki

3. Originally Posted by Salem
> ans = (1/3)* PIE *r2*h;
1/3 in integer maths is zero.

Make the expression a double.

SourceForge.net: Indentation - cpwiki
thanks for the reply, i just tried that and still zero

maybe am not making it well but it still give me zero
Code:
```# include <stdio.h>
# define PIE 3.14
double ComputeVolume ( float r, float h, double ans , float r2 );
int main () {
double ans;
printf (" Height : ");
scanf ("%f", & height );
ans = ComputeVolume (radius , height , ans , r2 );
printf (" Volume : %f\n", ans );
system("PAUSE");
return 0;
}
double ComputeVolume ( float r, float h, double ans , float r2)
{
r2 = r*r;
ans = (1/3)* PIE *r2*h;
return ans ;
}```
is it right like that to make the expression double?
i even tried to remove the (1/3) and still zero is appearing

4. Try
Code:
`(1.0/3.0)`

5. A few changes:

Code:
```# include <stdio.h>
# define PIE 3.14

double ComputeVolume (float r, float h);

int main () {
double vol;
printf (" Height : ");
scanf ("%f", &height );
vol = ComputeVolume (radius , height);
printf (" Volume : %f\n", vol);
system("PAUSE");
return 0;
}
double ComputeVolume (float r, float h)
{
double ans, r2;
r2 = r*r;
ans = (1.0/3.0)* PIE *r2*h;
return ans ;
}```

6. that was just great, thank you all for this great effort