Write four functions to compute the following properties of a sphere, given a diameter, d, which is
Question:
Write four functions to compute the following properties of a sphere, given a diameter, d, which is greater than or equal to 0.0: (a) Radius r = d/2 (b) Surface area = 4 × π × r 2 (c) Circumference = πd (d) Volume = 4π 3 × r 3
Make sure all output numbers align at their (implied) decimal point. Check to be sure your numbers are not less than zero, if so print an error message with the number that is incorrect butcontinueanyway. Use 3.14 for PI. Must also use FUNCTIONS. Each function must have a prototype and must have a return statement with 1 variable on it, NOT a calculation. NO use of global variables.
This is what i have so far, but this code just loops at the first printf even when the input is greater than 0. Also this is the first program with prototypes I do, so I don't yet understand how they are supposed to be used. I started with the radius function first, but the rest are also there.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14
#define SENTINEL 0
double radiusF(double diameter);
//double surfaceAreaF(double )
int main(void)
{
double diameter = 0;
double radius = 0;
double surfaceArea = 0;
double circumference = 0;
double volume = 0;
while(1)
{
printf("Diameter of sphere to calculate properties for?: ");
scanf("%i", &diameter);
if(diameter == SENTINEL) break;
if(diameter < 0)
{
printf("invalid entry\n");
printf("please try again\n");
continue;
}
}
return 0;
}
//----------------------------------------------------------------------------
double radiusF(double diameter)
{
double radius = 0;
radius = (diameter/2);
return radius;
}
------------------------------------------------------------------------------------
/*double surfaceAreaF (double raduis)
{
double radius = 0;
}
surfaceArea = (4.0*PI*(pow(radius,2.0)));
circumference = (PI*diameter);
volume = (((4.0*PI)/3.0)*(pow(radius,3.0)));
printf("Input:\tRadius:\tSurface Area:\t Circumference:\tVolume:\n");
printf("%10i %10i %10i %10i %10i\n\n", diameter, radius, surfaceArea, circumference, volume);
}
return 0;