I just started a new programming class last week, using the free Microsoft Visual C++. This is all new to me, so I apologize in advance if this seems like a very minor problem. Anywho, the program we're required to do this week is one where the user can enter in a radius, and the program will compute the surface area and volume of a sphere. I'm required to use doubles though, instead of floats, and our teacher said to use the #define function to define pi.
This is what I've come up with so far, and it doesn't seem to be working. I've been tweaking things here and there, but it doesn't seem to work. Can anybody point out where I've gone wrong? Thank you!
Code:
#include <stdio.h>
int main () {
double r;
double surface_area_sphere, volume_sphere;
#define pi 3.141593;
printf("Enter radius of sphere (cm): ");
scanf("%lf",&r);
printf("Radius: %lf\n",&r);
surface_area_sphere = 4.0*pi*r*r;
printf("Surface Area: %lf\n", surface_area_sphere);
volume_sphere = (4.0/3)*pi*r*r*r;
printf("Volume: %lf\n", volume_sphere);
return 0;
}