# New to programming, need help understanding what's wrong.

This is a discussion on New to programming, need help understanding what's wrong. within the C Programming forums, part of the General Programming Boards category; This is my code, basically i'm trying to write a program which find s the volume of spheres with certain ...

1. ## New to programming, need help understanding what's wrong.

This is my code, basically i'm trying to write a program which find s the volume of spheres with certain radius's. However it doesn't seem to be working, and is returning values of 0. Any clue as to why? Any help would be much appreciated

Code:
```#include <stdio.h>
#define Pi 3.14159265
double VolumeForRadius(double Radius)
{
double radius;
double volume = (4.0 / 3.0) * Pi * radius * radius * radius;
return volume;
}
int main(int argc, char *argv[])
{
printf("The volume of a sphere with radius %d is %f\n", 1, VolumeForRadius(1.0));
printf("The volume of a sphere with radius %f is %f\n", 4.657, VolumeForRadius(4.657));
printf("The volume of a sphere with radius %d is %f\n", 10, VolumeForRadius(10));
printf("The volume of a sphere with radius %d is %f\n", 42, VolumeForRadius(42));
}```

2. Code:
```double VolumeForRadius(double Radius)
{
double radius;
double volume = (4.0 / 3.0) * Pi * radius * radius * radius;
return volume;
}```
You define your function accepting a parameter "Radius" but never use it. Instead you declare a new variable "radius" which will have a garbage value because you don't initialize it and calculate "volume" from it.
You want to use the parameter in your calculation.

Bye, Andreas

Popular pages Recent additions