Skip to content

Feed the people

Count whole people supported by a food allocation.

  • Sinclair ZX Spectrum
  • BASIC

A food allocation is a proposal. Keep it in feed while grain still records everything in store. We can inspect the cost and warning before changing the settlement.

Replace line 2000.

Add lines 220, 2010, 2020, 2030, 2040, 2045, 2050, 2090, 2130, 2150, 2170, 2180, 2210.

yearfall.bas
  10 BORDER 0: PAPER 0: INK 7: CLS
 200 LET pop=60: LET grain=360: LET land=100: LET yr=1: LET lost=0
 220 LET feed=180
 270 GO SUB 2000
 280 STOP
2000 LET fed=INT (feed/3)
2010 IF fed>pop THEN LET fed=pop
2020 LET left=grain-feed
2030 LET ok=1: LET m$="All fed. Ready for harvest."
2040 IF fed<pop THEN LET m$=STR$ (pop-fed)+" people will starve."
2045 IF feed>3*pop THEN LET m$="Extra food gives no bonus."
2050 IF left<0 THEN LET ok=0: LET m$="Grain short by "+STR$ (-left)
2090 CLS
2100 PRINT AT 0,1; INK 6; BRIGHT 1;"YEARFALL";AT 0,20;"YEAR ";yr
2110 PRINT AT 2,1; INK 5;"PEOPLE ";pop;AT 2,17;"LAND ";land
2120 PRINT AT 3,1; INK 5;"GRAIN  ";grain
2130 PRINT AT 5,1; INK 4;"PLAN";AT 5,17;"AMOUNT";AT 5,25;"COST"
2150 PRINT AT 8,1;"F  Feed grain";AT 8,17;feed;AT 8,25;feed
2170 PRINT AT 11,1; INK 6;"Grain left: ";left
2180 PRINT AT 12,1;"Food needed: ";3*pop
2210 PRINT AT 16,1; INK 6;m$
2250 RETURN

RUN with feed set to 180. Sixty people need three grain each, so the screen should show 180 grain left and that everyone is fed. No grain has actually been spent: this checkpoint calculates and displays a plan, then stops.

Whole people, whole rations

INT (feed/3) counts complete three-grain rations. INT rounds down. With 179 grain, the result is 59; two spare grain do not form the sixtieth ration. Line 2010 caps fed at pop, so feeding 183 cannot create a sixty-first resident.

The proposed balance is grain-feed. An IF compares that balance with zero. ok is a numeric flag: one means the plan passes the checks so far, zero means it does not. We will use it to block a commitment later. At present it explains the displayed warning.

m$ is a string variable holding that warning. Spectrum string-variable names use one letter followed by $. STR$ converts a number into text, and + joins strings. This lets the message include the actual number of people who would go without food.

IF applies to the rest of its BASIC line. An assignment after THEN happens only when the comparison is true. Later warning assignments can replace earlier ones: a negative grain balance is a more immediate problem than whether everyone is fed.

What should the plan show with 179 grain allocated to food?

Show the explanation

59 people can be fed, one would starve, and 181 grain remains in the proposed budget. The stored population is still 60: this program has not committed the plan.

Change line 220 to LET feed=179 and RUN. Then try 361: spending more grain than exists should show a shortfall and set ok to zero. Restore line 220 to 180 afterwards. Food above the requirement costs grain but gives no extra benefit; the screen says so rather than leaving that rule to guesswork.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 3, chapter 7, chapter 9, chapter 13.

Run it here

This unit's program, built for you.

Program
yearfall.tap
Machine
ZX Spectrum 48K (PAL)

Download yearfall.tap