This program calculates how many days it will take a user to reach a target weight given a specified daily calorie intake. It models weight change using the approximation that one pound of body weight corresponds to 3,600 calories, and that maintaining a given weight requires 12 calories per pound per day. The program uses a iterative loop (lines 80–92) that repeatedly subtracts the daily calorie deficit or surplus from a running calorie total, incrementing a day counter each pass until the target weight’s calorie equivalent is reached. Results are output both to the screen and to a printer via LPRINT statements, and the program allows repeated calculations without restarting.
Program Structure
The program is organized into a linear sequence of input, validation, computation, and output phases. Lines 1–8 handle greeting and name input. Lines 15–27 initialize all numeric variables to zero. Lines 40–54 collect current and target weights. Lines 55–73 perform initial validation and advice. Lines 75–92 contain the iterative simulation loop. Lines 93–102 print the results. Lines 100–106 offer the user a repeat option, looping back to line 15 to reinitialize variables.
Calorie Model
The program uses two nutritional constants throughout:
- 3,600 calories per pound — used to convert weights to calorie equivalents (
C = A * 3600,D = B * 3600). - 12 calories per pound per day — used to estimate daily maintenance needs (
E = A * 12) and the advice thresholds (B * 12).
These are simplifications; the commonly cited figure for stored fat energy is approximately 3,500 calories per pound, and maintenance calorie needs vary considerably by individual. Nevertheless, the model is internally consistent and produces plausible day-count estimates for small weight changes.
Iterative Simulation Loop
Rather than computing the answer algebraically, lines 80–92 simulate the diet day by day:
- Line 80: Subtract the daily deficit/surplus from the running calorie total
C, whereE = A * 12is the maintenance level andFis actual intake:C = C - (E - F). - Line 81: Recompute the implied current weight from
C(thoughEis not updated, so maintenance calories remain fixed at the starting weight — a simplification). - Line 85: Increment day counter
G. - Lines 88–92: Branch depending on whether the goal is weight loss (
A > B) or gain (A < B), looping back to line 80 untilCcrosses the target calorie levelD.
Note that E on line 81 is recalculated from C but is immediately overwritten again on line 80 in the next iteration, so the recalculation at line 81 has no practical effect on the loop — it is vestigial code.
Variable Usage
| Variable | Purpose |
|---|---|
a$ | User’s name |
b$ | Yes/No response for repeat |
A | Current weight (pounds) |
B | Target weight (pounds) |
C | Running calorie total (starts at A * 3600) |
D | Target calorie total (B * 3600) |
E | Daily maintenance calories (recomputed each iteration, effectively unused) |
F | User’s planned daily calorie intake |
G | Day counter |
Input Validation
Line 55 checks for the trivial case where current and target weight are equal, printing a humorous rebuke and jumping to line 100 to skip the day calculation. Line 73 performs a more complex validation using a compound Boolean expression to detect when the user’s entered calorie intake F is on the wrong side of the maintenance threshold — for example, claiming to eat more than maintenance while trying to lose weight. If triggered, it prints “Don’t play games with me!” and jumps to line 107 (STOP), terminating rather than looping back for re-entry.
LPRINT Dual Output
The program systematically mirrors key output lines to both the screen (PRINT) and a printer (LPRINT), at lines 8, 94–97, 101–102. This pairing is consistent throughout, allowing the user to obtain a printed diet summary. The name entered at line 5 is also sent directly to the printer at line 8, providing a personalized header on the printout.
Content
Source Code
1 PRINT " DIET PROGRAM"
2 PRINT " "
4 PRINT "What is your name?"
5 INPUT a$
6 PRINT " "
7 PRINT a$
8 LPRINT a$
15 LET A=0
17 LET B=0
19 LET C=0
21 LET D=0
23 LET E=0
25 LET F=0
27 LET G=0
39 PRINT " "
40 PRINT "What is your weight?"
45 INPUT A
47 PRINT A;" POUNDS"
49 PRINT " "
50 PRINT "What weight do you desire?"
51 INPUT B
53 PRINT B;" POUNDS"
54 PRINT " "
55 IF A=B THEN PRINT "You are at your desired weight. Please don't waste my time!":GO TO 100
56 IF A>B THEN PRINT "You must consume less than ";B*12;" calories each day."
59 IF A<B THEN PRINT "You must consume an excess of ";B*12;" calories each day."
60 LET C=A*3600
65 LET D=B*3600
69 PRINT " "
70 PRINT "How many calories will you consume?"
71 INPUT F
72 PRINT F;" CALORIES"
73 IF (F >=B*12 AND B*12 <=A*12) OR (F <=B*12 AND B*12 >=A*12) THEN PRINT "Don't play games with me!":GO TO 107
75 LET E=A*12
80 LET C=C-(E-F)
81 LET E=C*12/3600
85 LET G=G+1
88 IF A<B THEN GO TO 92
90 IF C>D THEN GO TO 80
91 IF C <=D THEN GO TO 93
92 IF C<D THEN GO TO 80
93 PRINT " "
94 LPRINT "At ";F;" calories per day,"
95 PRINT "At ";F;" calories per day,"
96 LPRINT "it will take ";G;" days to reach ";B;" pounds."
97 PRINT "it will take ";G;" days to reach ";B;" pounds."
100 PRINT " "
101 LPRINT "You must consume ";B*12;" calories each day to maintain ";B;" pounds."
102 PRINT "You must consume ";B*12;" calories each day to maintain ";B;" pounds."
103 PRINT " "
104 PRINT "Do you require more data? Type YES or NO"
105 INPUT b$
106 IF b$="YES" THEN GO TO 15
107 STOP
200 SAVE "DIET" LINE 0
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
