#include const double pi = 3.14159265358979323846; #define SQUARE(x) ( ( x ) * ( x ) ) /* circle area by: A. C. Programmer date started: 12 Sept 2004 last updated: 2 Oct 2004 */ // Note: this program is horribly complicated for such a simple purpose. // I do not recommend that you write a simple program like this. // Simplicity is beauty. /* explain_program() explains the purpose of the program, displaying this on the screen of the computer */ void explain_program( void ) { cout << "This program calculates the area of a circle.\n"; cout << "Enter the value of the radius and press \n"; cout << endl; } /* get_value() prompts user to enter radius. Returns the value as a float. */ float get_value( void ) { float inputValue; /* value entered by user */ cout << "Value of the radius: "; cin >> inputValue; return inputValue; } /* circle_area() calculates the area of a circle. Returns the value as a float. */ float circle_area( float radius ) { float area; /* area of the circle */ area = pi * SQUARE( radius ); return area; } /* display_answer() displays the area of the circle on the screeen. */ void display_answer( float area ) { cout << "\n\n"; /* two blank lines */ cout << "The area of the circle is " << area << " square units.\n"; } int main( void ) { explain_program(); /* explains program to user */ float radius = get_value(); /* get radius from user */ float area = circle_area( radius ); /* compute the circle area */ display_answer( area ); /* display the answer */ }