# Thread: Noob Help......Calculating volume and area of a sphere...

1. Sorry, but I think that you really have to pause and read a tutorial on pointers. You need to understand how to work with pointers before you can proceed. At the moment, it looks like you have been making changes to your code without the faintest clue of why I have been suggesting what I have been suggesting.

EDIT:
Oh, I did not notice that in your post #23, you changed your correct line of code to:
Code:
`double *area, *radius, *volume;`
which is not correct. If area, radius and volume are pointers, what are they supposed to point to? Again, this means that you need to understand the concept of a pointer and how to use pointers effectively.

2. ^^^
AHH! okay makes perfect sense, I corrected that and now the program compiles!!

im not getting the desired output though lol

if i enter a radius of 25, i should get a volume of 65449.847 and an area of 7853.982, instead i'm getting a volume of 9.425 and an area of 25.133 :S

is it because im not returning anything from the calc?

Code:
```//INCLUDE SECTION
#include <stdio.h> //def's 4 printf, scanf, getchar, puts, gets, fflush
#include <conio.h> //def's for getch
#include <stdlib.h> //def's 4 system
#define PI 3.14159

//FUNCTION PROTOTYPES

void explanation(void);
void volume_calc(double *area, double *radius,double *volume);
void printresults(double area, double radius, double volume);

int main (void)
{
explanation();//FUNCTION CALL

printf("\n\t\t\tPRESS ANY KEY TO EXIT");
_getch();
return 0;
}

//FUNCTION DEFINITIONS
void explanation(void)
{
system ("cls");
puts ("This program will ask you to enter the RADIUS of a sphere...");
puts ("and then calculate the volume and surface area...");

}
void volume_calc( double *area, double *radius, double *volume)
{
//VARIABLE DECLARATIONS

//GET USER INPUT

//CALCULATIONS

//OUTPUT
}

{
printf("\nthe volume of this sphere is ==> %.3f", volume);
printf("\n\ntthe area of this sphere is ==> %.3f", area);
}```

3. It's mainly because you have 4/3 when computing your volume. 4/3 is assumed by the compiler to be an integer division and the result is 1. What you probably want is a floating point result so just do 4.0/3.0 instead of 4/3.

4. ^^^
yeah just noticed that, gave it a quick fix the numbers are a bit better, but still way off.....

for some reason the radius is coming up as -92556900000000000000.000 when i display it at the end....can't seem to figure this one out.. hmmmmm

5. Originally Posted by matt.s
^^^
yeah just noticed that, gave it a quick fix the numbers are a bit better, but still way off.....

for some reason the radius is coming up as -92556900000000000000.000 when i display it at the end....can't seem to figure this one out.. hmmmmm

or at least it does according to my teacher, who could very well be wrong lol

7. ummm... NO!

If you wanted to do that you would write x = pow(radius,100); pow is a function defined in math.h

8. ^^^^^
ahhh i see what your saying their, my teacher has clearly lost the plot i think lol :P

ahhhhhh its still giving me the wrong output! how can such a simple little program be so confusing!?! :S

Code:
```//INCLUDE SECTION
#include <stdio.h> //def's 4 printf, scanf, getchar, puts, gets, fflush
#include <conio.h> //def's for getch
#include <stdlib.h> //def's 4 system
#define PI 3.14159

//FUNCTION PROTOTYPES

void explanation(void);
void volume_calc(double *area, double *radius,double *volume);
void printresults(double area, double radius, double volume);

int main (void)
{
explanation();//FUNCTION CALL

printf("\n\t\t\tPRESS ANY KEY TO EXIT");
_getch();
return 0;
}

//FUNCTION DEFINITIONS
void explanation(void)
{
system ("cls");
puts ("This program will ask you to enter the RADIUS of a sphere...");
puts ("and then calculate the volume and surface area...");

}
void volume_calc( double *area, double *radius, double *volume)
{
//VARIABLE DECLARATIONS

//GET USER INPUT

//CALCULATIONS

//OUTPUT
}

{
printf("\nthe volume of this sphere is ==> %.3f", volume);
printf("\n\ntthe area of this sphere is ==> %.3f", area);
}```

9. What's the input and output now?

10. Input: 25

Output:
You entered a radius of -925596047186160310000000000000000000000000.000...
The Volume of the sphere is: -33164118186955090000000000000000000000000000.000.. ...
The Area of the sphere is: 10765953004987781000000000000000000000000000.000.. ..

11. Try printing %lf

12. ^^
same output

kinda whack no? :S

13. scanf ("%lf", radius); <--- correct

You undo and do an indirect, which means you put neither. Also the %lf again for double.

14. Ohhhh i was doing the %lf in the wrong place! and your right, its working perfect now! Thank you so much, greatly appreciated!!!!

15. Nice catch! I didn't see that coming.