JDog JDog -4 years ago 170
C Question

How would I set up function to calculate the area of a circle - C

I have this C program that needs to calculate the area of a circle that a user inputs.
I have to use this before the main function:

void area_circum(double radius, double *area, double *circum);


I'm having trouble getting the program to work. I'm using the main function and another one called area_circum();

This is what I have right now:

#include <stdio.h>


void area_circum(double radius, double *area, double *circum);

int main(void) {

double radius, area, circum;

printf("Please enter the radius of the circle: ");
scanf("%f", &radius);

area_circum(radius, area, circum);

printf("Area of circle : %0.4f\n", area);

return 0;
}


void area_circum(double radius, double *area, double *circum) {
double PIE = 3.141;

double areaC = 0;

areaC = PIE * radius * radius;
}


When I build it and run it, it works, I input a number, but then it returns 0.00

Answer Source
#include <stdio.h>

void area_circum(double radius);

int main() {

   double radius;

   printf("Please enter the radius of the circle: ");

   scanf("%lf", &radius);

   area_circum(radius);

   return 0;

}


void area_circum(double radius) {

   double PIE = 3.141;

   double areaC = 0;

   areaC = PIE * radius * radius;

   printf("Area of circle : %0.4f\n", areaC);

}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download