Dynamic Web Sites - Exercises with Examples

Fun With Functions...

You were first introduced to functions with the print() statement. Next, you read about functions in your reading assignment. Finally, you studied a simple function in class. Now you're going to expand on what you learned in class, by extending a simple calculator.

First, review a completed calculator program that demonstrates the example illustrated in class. You're welcome to view its rendered output. Not terribly interesting, especially since no HTML markup has been applied. We'll worry about that later... Finally, here is a sparingly commented version, to help you see what little code we actually wrote. Not convinced? Do the comments still obscure the program code, in your view? Try this comment-free version! (Does the lack of comments make the code easier or more difficult to follow?)

Exercise #4

A. Make your own copy of the source code from above (you may opt for the sparingly commented version if you find it easier to work with). Add the following functions into the "Calculator Function Library," making certain to follow the same format represented by the Add() function :

Note: for Percent(), calculate b percent of a using the formula a * (b / 100).

B. Using the preferred approach identified within the commented version above, write the additional statements needed to use each function and display its results.

Reference: As you start on part A. above, you may want to review the handy PHP Operators reference guide, which identifies the Arithmetic Operators, their symbols, and examples of their use.