Payroll

This file is part of Timex Sinclair Public Domain Library Tape 1003 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000

This program calculates an employee’s gross pay based on hours worked, applying a standard overtime rule. For up to 40 hours, pay is computed at a flat rate of $7 per hour. Hours beyond 40 are paid at time-and-a-half ($10.50/hour). Entering a negative value for hours terminates the program via STOP at line 70. The program loops continuously via line 65, prompting for successive payroll entries until a negative sentinel value is entered.


Program Analysis

Program Structure

The program is a short, self-contained loop with a single input/output cycle. It prompts for hours worked, branches based on the value entered, computes pay, prints the result, and repeats. A negative input value serves as a sentinel to exit the loop.

  1. Lines 10–12: Prompt, accept, and echo the hours value.
  2. Lines 15–20: Two conditional branches — exit on negative input, jump to overtime calculation if hours exceed 40.
  3. Lines 30–40: Standard-time pay calculation (P = 7 * H), then skip to output.
  4. Line 50: Overtime pay calculation with time-and-a-half for hours over 40.
  5. Lines 60–65: Print result and loop back to line 10.
  6. Line 70: STOP — reached only by negative input sentinel.

Pay Calculation Logic

The base rate is $7.00/hour. The two pay formulas used are:

ConditionFormulaLine
H ≤ 40P = 7 * H30
H > 40P = 7 * 40 + 1.5 * 7 * (H - 40)50

The overtime formula correctly pays the first 40 hours at the base rate and applies a 1.5× multiplier only to the excess hours. This is a textbook application of a piecewise pay function.

Key BASIC Idioms

  • Sentinel value: A negative hours value (line 15) is used to signal end-of-data and branch to STOP, a common idiom when EOF detection is unavailable.
  • Unconditional loop: GOTO 10 at line 65 creates an infinite loop, relying entirely on the sentinel to exit — there is no FOR/NEXT or conditional loop structure.
  • Echo of input: Line 12 prints H immediately after input, providing visual confirmation of the entered value before processing.

Anomalies and Minor Issues

  • Zero hours: An input of H = 0 is valid and will correctly return a pay of $0, though it may not be meaningful in practice.
  • No input validation beyond sign check: Fractional or very large hour values are accepted without further bounds checking.
  • Line 90 (RUN): A RUN statement following a SAVE is a common idiom to restart execution after saving, but since SAVE is on line 80 and STOP is on line 70, normal program flow never reaches line 80 — these lines are only reachable if the user manually runs them or if execution falls through in an unusual way.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10122 – 10175.

Related Products

Related Articles

Related Content

Image Gallery

Payroll

Source Code

   1 REM PAYROLL
  10 PRINT "ENTER HOURS WORKED"
  11 INPUT H
  12 PRINT H
  15 IF H<0 THEN GOTO 70
  20 IF H>40 THEN GOTO 50
  30 LET P=7*H
  40 GOTO 60
  50 LET P=7*40+1.5*7*(H-40)
  60 PRINT "PAY IS:$ ";P
  65 GOTO 10
  70 STOP 
  80 SAVE "1012%6"
  90 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top