#include <iostream> using namespace std; //Function prototype - either the function must be declared in its entirety //before it's used or, alternatively, this prototype must appear so that the //compiler knows what kinds of arguments and return value this function uses. float area_of_circle(float radius); main() { //A simple example of calling the function and checking sensible output float radius = 1.0; cout << "Area of circle with radius " << radius << " is " << area_of_circle(radius) << endl; //Compare the non-function versions to do the same calculation twice: float radius_1 = 1.0; float radius_2 = 2.0; //Note we could have an error, as in the line below... float area_1 = M_PI * radius_1; //...but not in this line, even though it's meant to be the same formula. float area_2 = M_PI * radius_2 * radius_2; //By using the function instead of writing it out explicitly every time //we can make debugging much easier. } //Function definition //This function calculations the area of a circle with a given input radius float area_of_circle(float radius) { float area = M_PI * radius * radius; return area; }