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

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;

Step by Step Solution

3.37 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

include include include define PI 314 define SENTINEL 0 function prototypes double radiusFdouble diameter double surfaceAreaFdouble diameter double ci... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!

Related Book