Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 but continue anyway. 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 #include #include

#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 "); printf("please try again "); 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: "); printf("%10i %10i %10i %10i %10i ", diameter, radius, surfaceArea, circumference, volume); }

return 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions