Classic Computer Magazine Archive ANTIC VOL. 5, NO. 2 / JUNE 1986

RECIPE CONVERTER

CALCULATES THOSE INGREDIENT CHANGES

by JAMES BROWN



Type a recipe into your Atari and Recipe Converter will calculate how much more of each ingredient you need for serving more people-or how much less you need for serving fewer people. Also converts decimal measurements to metric and vice versa. The BASIC program will run on any Atari 8-bit computer with at least 48K and a disk drive.


It's time for a big family feast and 12 people are coming to dinner. But-oh no! Your favorite recipe makes only five servings and you need to scale it upward.

Only three of you will be home next weekend and that same recipe is now too big. You need to scale it down.

Or how about this? You just got a mouth-watering French cookbook for your birthday and you really want to try that Navarin Printanier-but all the ingredients are in metric! Just how many cups are there in a liter of heavy cream?

These everyday problems call for a lot of scratch paper and a heavy-duty pencil. Or ... a computer.

TYPING IT IN
Type in Listing 1, RECIPE.BAS, check it with TYPO II and SAVE a copy before you RUN it.

Easier said than done, huh? Okay, this is a pretty long program listing, but at least it doesn't have many strange characters. If you're a newcomer, take your time. Don't try to get it done all in one sitting. And be sure that every TYPO II code matches. Be careful to type the DATA statements exactly as shown, including spaces in the REM statements in lines 210 to 255. Also, check to make sure you don't omit any program lines. TYPO II can't check for this.

KEEP IT FRIENDLY
In order to make Recipe Converter easy to use without digging out an instruction manual and decimal conversion table every time you run it, a lot of attention had to be paid to the user interface. (This is called friendly programming.)

For this reason, most of the program is dedicated to getting the information into the computer, and getting the results out. Only a small fraction of the code actually does any computational work. This is fairly typical of "practical" applications. You will find a lot of ideas in this program to help you write your own "user-friendly" applications.

Instructions for using the program appear on the screen as you need them. The screen border color and sound cues tell you whether the screen is waiting for input, or contains only instructions, or displays an error message.

USING THE PROGRAM
To use Recipe Converter you need a cookbook or other recipe source, a pencil and a sheet of paper. A printer is optional. You can save your recipes to disk and recall them later if you think you will need to "multiply" them again.

Recipe Converter can scale recipes up or down by any reasonable amount. However, some recipes don't work well when increased by a large amount, so be careful. Also, cooking times do not scale easily, so you will have to use your experience here.

Although all necessary instructions are in the program, let's step through an example. When the program is RUN, a colorful-and musical-title screen will appear followed by a screen describing the steps you will be going through to convert your recipe. After reading the screen, press [RETURN] to continue.

A second screen reminds you to search out all ingredients in your recipe-and, perhaps, label them with numbers. Press [RETURN] and you will be presented with your first decision: Is your recipe in English or metric measurement? Or, maybe you previously saved a recipe to disk and now want to reload it. Those users who have never seen the program before can type [H] for a HELP screen which will explain how to tell the difference between English and metric. Like we said, this is a friendly program.

FRESH FRUIT
Okay, now that you've seen how friendly it is, let's zip through a recipe. We're going to take the following recipe for Fresh Fruit Salad, which serves six, and adjust it for 12 people. (We'll let you convert it to metric.) Some of the specific steps described below will make more sense once you actually have the program up and running.

FRESH FRUIT SALAD

2 peaches, skinned and pitted

1 small melon

3 apricots, pitted

1 3/4 cups strawberries

2 cups pitted cherries

2 Tbsp sugar

3 Tbsp orange juice

3 Tbsp lime juice

   Press [E], for English measurements. Some instruction screens will show you what to do next. At the prompt, press [P] twice to enter 2 peaches. At the next screen, choose [P] again, for "piece", since a peach is a unit.

Now you may type in the description of the ingredient. In this case, type PEACHES [RETURN]. A verification screen will appear with ingredient #1-2 piece of-PEACHES. Sounds strange, but it's accurate.

All right, enter the rest of the ingredients in the same fashion. Our first three ingredients are units. When you get to the strawberries, choose cups. If you make a mistake entering, just press [N] when prompted. When all the ingredients are entered, press [Z].

We want to double our recipe, so we choose [M], then [P]. And let's look at it in English by choosing [E]. Each ingredient will be displayed on the screen, one at a time-both with the original count and the converted amount. If you don't have a printer, jot down the new amounts in your cookbook. (In some cases, an adjusted recipe may call for a fractional amount-such as 1 3/4 eggs. Just round this off, or use smaller eggs.) Notice when you get to the strawberries, you have a choice of equivalent cups, pints, quarts, and gallons. Choose whichever is more practical for you.

After you have stepped through the entire menu, a new screen will appear with several choices. Those with a printer can print a hard copy of the same information that earlier printed to screen. This might be a good opportunity to save your recipe to disk. (Don't forget to include D:.)

PROGRAM TAKE-APART
With the exception of a few short routines at the end, subroutines start at line numbers ending in 00 and end at line numbers ending in 99. The various portions of the program are:

100-142 Array declarations and definitions.

200-321 Data values for fractions, units, conversions, etc., plus note values for theme music.

1000-1099  Main program.

1100-1199 Initialization of arrays and constants. Line 60 disables the [BREAK] key (some people press it by accident because it is near the [RETURN] key).

1200-1299 Display the title page and play theme music.

1300-1399 Display introductory instructions.

1400-1499 Determine kind of input.

1500-1599 Determine amount to multiply recipe by.

1600-1699 Enter the ingredients for the recipe.

1700-1799 Enter the quantity for an ingredient.

1900-1999 Enter the units for an ingredient.

2100-2199 Display an ingredient.

2200-2299 Enter the name for an ingredient.

2500-2599 Choose metric or English units for output.

2600-2699 Display the converted recipe.

2700-2799 Display all reasonable combinations of quantity and units which are equivalent.

2800-2899 For English units, find the nearest fraction to the converted value. Approximations are used since cooking is not an exact science anyway. Decimals are traditionally used with metric units.

2900-2999 Ending menu.

3000-3999 Read a recipe from disk.

3100-3199 Print a recipe, including conversions.

3200-3299 Display a converted recipe.

3500-3599 Save a recipe to disk.

3700-3799 Check that all optional information, such as number of servings and a title, has been specified prior to printing or saving to disk.

4000-4099 Open a disk file.

7000-7099 Change an ingredient.

7100-7199 Enter an ingredient.

8000-8099 Assorted prompting routines.

8100-8199 Get a single letter and convert to upper case.

8200-8230 Extend a string with blanks.

8300-8399 Error handler for file open error.

Miscellaneous technical goodies:

INPUT #16,T$, in line 8014 waits for input without the "?" prompt.

POKE 702,64, in line 8110 is the same as pressing [SHIFT] [CAPS]. This insures all input is in capital letters.

POKE 694,0, in line 8115 shuts off inverse, again, to insure uniform input.

James Brown is manager of the Computer Science and Applications Section of tbeJet Propulsion Laboratory, California Institute of Technology in Pasadena.

Listing 1   RECIPE.BAS Download