< previous page page_33 next page >

Page 33
The next step is to compute the wages. Let's apply means-ends analysis. Our starting point is the set of data values that was input; our desired ending, the payroll for the week. We know that if there is no overtime, wages are simply the pay rate times the number of hours worked. If the number of hours worked is greater than 40, however, wages are 40 times the pay rate, plus the number of overtime hours times one and a half times the pay rate. The number of overtime hours is computed by subtracting 40 from the total number of hours worked. To figure the wages, we take the following steps:
If hours worked is greater than 40.0, then
   wages = (40.0 × pay rate) + (hours worked - 40.0) × 1.5 × pay rate
otherwise
  wages = hours worked × pay rate
The last step, outputting the results, is simply a matter of having the computer write the employee number, the pay rate, the number of hours worked, and the wages onto payFile:
Write the employee number, pay rate, hours worked, and wages onto payFile.
There are two things we've overlooked. First, we must repeat this process for each employee, and second, we must compute the total wages for the week. Let's use the building-block approach to combine our three main steps (getting the data, computing the wages, and outputting the results) with a structure that repeats the steps for each employee as long as the employee number is not 0. When the employee number is 0, this structure will skip to the end of the algorithm. Next we'll insert a step just after the wages are computed that adds them to a running total.
Finally, we must take care of a couple of housekeeping chores. Before we start processing, we must prepare the output file to receive the results and set the running total to zero. At the end of the algorithm, we must tell the computer to stop processing.
What follows is the complete algorithm. Calculating the wages is written as a separate subalgorithm that is defined below the main algorithm. Notice that the algorithm is simply a very precise description of the same steps you would follow to do this process by hand.
Main Algorithm
Prepare to write a list of the employees' wages (open file payFile)
Set the total payroll to zero
Prompt the user for the employee number (put a message on the screen)
Read the employee number

 
< previous page page_33 next page >