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.
- Lines 10–12: Prompt, accept, and echo the hours value.
- Lines 15–20: Two conditional branches — exit on negative input, jump to overtime calculation if hours exceed 40.
- Lines 30–40: Standard-time pay calculation (
P = 7 * H), then skip to output. - Line 50: Overtime pay calculation with time-and-a-half for hours over 40.
- Lines 60–65: Print result and loop back to line 10.
- 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:
| Condition | Formula | Line |
|---|---|---|
| H ≤ 40 | P = 7 * H | 30 |
| H > 40 | P = 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 whenEOFdetection is unavailable. - Unconditional loop:
GOTO 10at 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
Himmediately after input, providing visual confirmation of the entered value before processing.
Anomalies and Minor Issues
- Zero hours: An input of
H = 0is 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): ARUNstatement following aSAVEis a common idiom to restart execution after saving, but sinceSAVEis on line 80 andSTOPis 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
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.
