Life Expectancy

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

This program estimates a user’s life expectancy by asking a series of lifestyle and demographic questions, then computing a projected age at death separately for male and female outcomes. It starts with a base age value of 71 stored in variable A, then adjusts it up or down based on marital status, financial comfort, exercise habits, stress, smoking, alcohol consumption, illness frequency, and excess body weight. The subroutine at line 54 acts as a simple screen-clear-and-padding routine, calling CLS followed by three blank PRINT statements to create visual breathing room between questions. Notable is the deduction formula at line 51–52, where overweight pounds (P, accumulated in C) and alcohol score (G) are applied as fractional penalties, with females receiving a flat +7 year bonus.


Program Analysis

Program Structure

The program is a linear questionnaire with a single subroutine. Execution flows from line 1 through line 53 (STOP), collecting user responses and adjusting a running score in variable A. The subroutine at lines 54–58 is called repeatedly via GOSUB 54 to clear the screen between prompts. Lines 60 and 65 are utility lines (SAVE and RUN) that are never reached during normal execution.

Variable Usage

VariablePurpose
ABase life expectancy estimate, initially 71 (adjusted throughout)
BUser’s current age in years
CAccumulated overweight pounds (used as a penalty divisor)
GAlcohol score (0, 5, or 10 entered by user)
PNumber of pounds overweight (added to C)
A$Married? response
C$Financially well off? response
D$Overweight? response
E$Exercise frequency response
F$Tense/stressed? response
H$Smoker? response
K$Often ill? response

Scoring Logic

The base score A starts at 71 and is modified by the following rules:

  • Married (A$="YES"): A set to 76 (overrides current value)
  • Financially comfortable (C$="YES"): A = A - 3 (anomaly — see below)
  • Exercises sometimes: A = A + 3
  • Exercises often: A = A + 5
  • Often tense: A = A - 3
  • Not tense: A = A + 3
  • Smoker: A = A - 5
  • Often ill: A = A - 3
  • Not often ill: A = A + 3
  • If current age B > A: A = B + (B - A) / 2 (age already exceeds estimate)

The final output applies additional penalties: overweight deduction is C/5 and alcohol deduction is G. Females receive a flat +7 year bonus over males.

Notable Techniques

The subroutine at line 54 is called both before and after some questions (e.g., lines 23 and 29 both call it around the exercise question), resulting in double screen clears in some flows. This is likely a copy-paste artifact rather than intentional design.

Line 38 handles the edge case where the user’s current age already exceeds the calculated estimate, pushing A further beyond B using a linear extrapolation: A = B + (B - A) / 2. Note that at this point B > A makes B - A positive, so the result is correctly higher than B.

Bugs and Anomalies

  • Financial comfort reduces lifespan: Line 15 subtracts 3 from A if the user was financially well off (C$="YES" THEN LET A=A-3). This is counter-intuitive and is almost certainly a sign error — the intended adjustment was probably A+3.
  • Married overwrites rather than adjusts: Line 10 sets A=76 rather than adding to the base of 71, meaning the marriage bonus is always exactly +5 regardless of prior state. If A had already been modified (it hasn’t at this point), the value would be lost.
  • Alcohol input not validated: The program trusts the user to enter exactly 0, 5, or 10 for the drink question; any numeric value is accepted and used directly as a deduction.
  • Overweight logic skips input when age < 40: Line 19 jumps to line 24 if B<40 regardless of D$, but the weight question has already been displayed. If the user answered “YES” to being overweight but is under 40, no pounds are recorded — this may be intentional (younger people’s weight is treated as less significant) but is not communicated to the user.
  • Double CLS calls: Lines 23 and 29 both call GOSUB 54 flanking the exercise question (lines 24–28), causing the screen to be cleared twice in quick succession on that path.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10051 – 10121.

Related Products

Related Articles

Related Content

Image Gallery

Life Expectancy

Source Code

   1 LET C=0
   2 PRINT "%L%I%V%E%S"
   3 LET A=71
   4 PRINT ,"AGE(YRS.)?"
   5 INPUT B
   6 GOSUB 54
   7 PRINT ,"MARRIED?"
   8 INPUT A$
   9 GOSUB 54
  10 IF A$="YES" THEN LET A=76
  11 PRINT "HAVE YOU BEEN FAIRLY  WELL OFF"
  12 PRINT "FINANCIALLY,MOST OF YOUR LIFE?"
  13 INPUT C$
  14 GOSUB 54
  15 IF C$="YES" THEN LET A=A-3
  16 PRINT "ARE YOU OVERWEIGHT?"
  17 INPUT D$
  18 GOSUB 54
  19 IF D$="NO" OR B<40 THEN GOTO 24
  20 IF D$="YES" THEN PRINT ,"BY HOW MANY POUNDS?"
  21 INPUT P
  22 LET C=C+P
  23 GOSUB 54
  24 PRINT "EXERCISE?-NEVER/SOMETIMES/OFTEN"
  25 INPUT E$
  26 GOSUB 54
  27 IF E$="SOMETIMES" THEN LET A=A+3
  28 IF E$="OFTEN" THEN LET A=A+5
  29 GOSUB 54
  30 PRINT "ARE YOU OFTEN TENSE?"
  31 INPUT F$
  32 GOSUB 54
  33 IF F$="YES" THEN LET A=A-3
  34 IF F$="NO" THEN LET A=A+3
  35 PRINT "DRINK? LITTLE=0/MODERATE=5"
  36 PRINT ,"HEAVY=10)"
  37 INPUT G
  38 IF B>A THEN LET A=B+(B-A)/2
  39 GOSUB 54
  40 PRINT "DO YOU SMOKE?"
  41 INPUT H$
  42 IF H$="YES" THEN LET A=A-5
  43 GOSUB 54
  44 PRINT "OFTEN ILL?"
  45 INPUT K$
  46 IF K$="YES" THEN LET A=A-3
  47 IF K$="NO" THEN LET A=A+3
  48 GOSUB 54
  49 PRINT "EST. AGE AT DEATH:"
  50 PRINT 
  51 PRINT ,"FEMALE-- ";A+7-C/5-G
  52 PRINT ,"MALE---- ";A-C/5-G
  53 STOP 
  54 CLS 
  55 PRINT 
  56 PRINT 
  57 PRINT 
  58 RETURN 
  60 SAVE "1005%2"
  65 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