3
Applications and Education
CalCalc: Computerize Your Diet
Charles Brannon
This program can help you lose weight by cutting calories. Be sure to consult your doctor before using this program or any other weight-loss technique.

Calorie counting is important in most diet plans. Unfortunately, the process of looking up every item of food you eat is discouragingly tedious. And even if you conscientiously keep track of calories, how do you know how much progress you're making?

Your body burns a certain number of calories per day. The number depends on your sex, build, and activities. In order to lose weight, you must eat fewer calories than your body needs, forcing it to convert fat tissue into carbohydrates. On the other hand, if you eat more calories than your body burns in one day, the excess is converted into fat.

3500 Calories = 1 Pound

In order to lose one pound of fat, you have to miss 3500 calories. In order to gain a pound, you have to have an excess of 3500 calories. This is not on a daily basis; calories accumulate. So if you ate 1000 more calories each day than your body used, you would gain one pound in about three and a half days.

Since any calculation is spread over many days, it can be hard to see progress, or to forecast how long it will take to shed excess weight. The computer is of great aid here.

"CalCalc" asks you a number of questions, such as your sex and age, to determine how many calories you need each day. You then enter everything you?ve eaten at the end of the day, selecting foods and quantities from a list (a menu, appropriately enough). Just press the letter corresponding to the food you ate. If you don?t see a certain food, press RETURN to see more items.

Adding to the Menu

What if you ate a food not on the list? This is not too hard, since we've included only a sample selection of foods, found in the DATA statements from lines 1140 and up. To customize this list to your preferences and habits, just purchase a pocket-sized calorie counter (available at most grocery-store checkout counters). Then add to or change the DATA statements.

There is one DATA statement for each food. The first item on the line (after the word DATA) is the name of the food. Make the name less than 20 letters long. The next item, preceded with a comma, is the number of calories in an average serving, followed by a comma, and the description of the average serving, such as 1 CUP or one 8" EAR. The last DATA statement (line 1500 here) should be END,0,0 which marks the end of the list.

After you've pressed the letter corresponding to the food you've eaten, the computer will display the quantity (such as one cup) and calories of an average serving. You enter the multiple or fraction in decimal of the quantity given. For example, if you drank two glasses of milk for breakfast, enter a 2 for two one-cup portions. If you had half a medium orange, enter 0.5. CalCalc then displays the calories for the food consumed, and the cumulative total of calories. You continue to enter foods for everything you've eaten.

Guesstimating

You can also approximate calories. For example, if you ate a chicken-filet sandwich, you could select T, chicken (one 4-ounce serving), and K, two one-slice portions of white bread. Or if you can look on the wrapper of the product, you can enter the calories directly. Just press the number sign, #, instead of a letter and enter the calories literally.

The Moment of Truth

After you've finished entering all the foods, the computer is ready to forecast weight loss. It bases this forecast on the assumption that you will eat about the same number of calories each day. Just enter the number of days you want to "look ahead," and CalCalc will tell you how much weight you will have lost. If you're eating too much, it will, with equal placidity, show you how much you'll have gained.

CalCalc makes dieting much easier. It goes beyond mere automation of a calorie counter by letting you see the effect of changes. By cutting down on meals and checking your total calories wiht CalCalc, you can see if you'll lose weight.

CalCalc
100 GRAPHICS 0:POKE 752,1:GOSUB 1020:DIM A$(1),FOOD$(19),AMOUNT$(10)
105 OPEN #1,4,0,"K":POKE 82,0
110 PRINT "{DOWN}WARNING: CONSULT YOUR DOCTOR BEFORE"
120 PRINT "{9 SPACES}USING THIS PROGRAM OR ANY"
130 ? "{9 SPACES}OTHER WEIGHT-LOSS TECHNIQUE."
140 ? "{DOWN}ARE YOU MALE OR FEMALE?"
150 GET #1,A:A$=CHR$(A):IF A$<>"M" AND A$<>"F" THEN 150
160 SX=0:IF A$="F" THEN SX=1
170 IF SX=0 THEN 200
180 ? "{DOWN}ARE YOU PREGNANT";:GOSUB 980:IF YES THEN PREG=1
190 ? "{DOWN}ARE YOU NURSING";:GOSUB 980:IF YES THEN NU=1
200 GOSUB 1020
210 ? "ENTER 0 IF NOT KNOWN:":? 
220 TRAP 220:? "{UP}{UP}NUMBER OF CALORIES CONSUMED?0{2 LEFT};:POKE 752,0:INPUT CAL:POKE 752,1:TRAP 40000"
230 IF CAL<0 THEN PRINT "{DOWN}{BELL}IMPOSSIBLE":GOTO 200
240 IF CAL>=4500 THEN PRINT "{DOWN}";CAL;"CALORIES? ARE YOU SURE";:GOSUB 980:IF 1-YES THEN 200
250 IF CAL THEN 730
260 PX=0:PY=10:GOSUB 1020
270 FOR I=1 TO 26
280 READ FOOD$,CL,AMOUNT$
290 IF FOOD$="END" THEN 330
300 POSITION PX,PY:? CHR$(I+192);":";FOOD$:PY=PY+1
310 IF I=13 THEN PX=20:PY=10
320 NEXT I
330 REM 
340 IF PEEK(20)>60 AND PEEK(20)<120 THEN POSITION 2,23:? "ENTER # OR LETTER OF FOOD";
350 IF PEEK(20)>120 AND PEEK(20)<180 THEN POSITION 2,23:? "PRESS RETURN TO GO ON{5 SPACES}";
360 IF PEEK(20)>180 THEN POSITION 2,23:? "PRESS * WHEN DONE{4 SPACES}";:POKE 20,0
365 IF PEEK(764)=255 THEN 340
370 GET #1,A:A$=CHR$(A):IF (A$<"A" OR A$>"Z") AND A$<>CHR$(155) AND A$<>"*" AND A$<>"#" THEN 340
380 IF A$<>CHR$(155) THEN 410
390 NX=NX+1:IF FOOD$="END" THEN RESTORE :NX=0
400 GOTO 260
410 RESTORE 
420 IF A$="#" THEN 600
430 IF A$="*" THEN 660
440 FOR I=1 TO NX*26+ASC(A$)-64
450 READ FOOD$,CL,AMOUNT$
460 NEXT I
470 GOSUB 1020
480 PRINT "FOOD: ";FOOD$
490 PRINT "CALORIES PER ";AMOUNT$;":";CL
500 PRINT "{DOWN}ENTER QUANTITY OF ABOVE FOOD"
510 PRINT "CONSUMED, USING A MULTIPLE OR":? 
520 TRAP 520:PRINT "{UP}{UP}A DECIMAL FRACTION?0{2 LEFT}";:POKE 752,0:INPUT QU:POKE 752,1:TRAP 40000
530 IF QU=0 THEN 590
540 IF QU<0 THEN PRINT "{DOWN}{BELL}IMPOSSIBLE":FOR W=1 TO 500:GOTO 470
550 PRINT "{DOWN}CALORIES OF ";FOOD$;":";CL*QU
560 PRINT "{DOWN}CALORIES CONSUMED SO FAR:";:CAL=CAL+CL*QU:PRINT CAL
570 ? "{2 DOWN}PRESS RETURN TO CONTINUE..."
580 GET #1,A:A$=CHR$(A):IF A$<>CHR$(155) THEN 580
590 RESTORE :NX=0:GOTO 260
600 GOSUB 1020:? "{DOWN}ENTER ABSOLUTE QUANTITY"
610 ? "{DOWN}OF CALORIES FOR FOOD NOT ON LIST:":? 
620 TRAP 620:? "{UP}{UP}?0{2 LEFT}";:POKE 752,0:INPUT CL:POKE 752,C1:TRAP 40000
630 IF CL=0 THEN NX=0:GOTO 260
640 IF CL<0 THEN ? "{DOWN}{BELL}IMPOSSIBLE":FOR W=0 TO 5000:NEXT W:GOTO 600
650 QU=1:GOTO 560
660 GOSUB 1020
670 PRINT "TOTAL CALORIES CONSUMED:";CAL
680 ? "{2 DOWN}DOES THAT SOUND REASONABLE";:GOSUB 980
690 IF YES THEN 730
700 ? "{DOWN}DO YOU WANT TO":? "RE-ENTER THE CALORIES";:GOSUB 980
710 IF YES THEN CAL=0:GOTO 260
720 PRINT "{CLEAR}":END 
730 GOSUB 1020:? :? 
740 TRAP 740:PRINT "{UP}{UP}WHAT IS YOUR AGE?20{3 LEFT}";:POKE 752,0:INPUT AGE:POKE 752,1:TRAP 40000
750 IF AGE<20 OR AGE>70 THEN PRINT "{DOWN}YOU MUST BE BETWEEN 20 AND 70"
760 IF AGE<20 OR AGE>70 THEN FOR W=1 TO 300:NEXT W:GOTO 730
770 IF AGE>=20 OR AGE<30 THEN CPD=3200:IF SX THEN CPD=2300
780 IF AGE>30 AND AGE<40 THEN CPD=3104:IF SX THEN CPD=2231
790 IF AGE>40 AND AGE<60 THEN CPD=2768:IF SX THEN CPD=1990
800 IF AGE>60 AND AGE<70 THEN CPD=2528:IF SX THEN CPD=1587
810 CPD=CPD+1000*NU+450*PREG
820 ? "{DOWN}ON A SCALE OF 1-5"
830 ? "1=MODERATELY ACTIVE, 5=VERY ACTIVE"
840 ? "HOW ACTIVE ARE YOU?"
850 GET #1,A:A$=CHR$(A):IF A$<"1" OR A$>"5" THEN 850
860 CPD=CPD+VAL(A$)*200
870 GOSUB 1020:? "{DOWN}ESTIMATED ENERGY EXPENDITURE":? "IN CALORIES IN ONE DAY:";CPD
880 ? "{DOWN}TOTAL CALORIC INTAKE IN ONE DAY:";CAL
890 DF=CAL-CPD
900 ? "{DOWN}NUMBER OF DAYS TO PROJECTED"
910 TRAP 910:? "WEIGHT LOSS/GAIN?1{2 LEFT}";:POKE 752,0:INPUT ND:POKE 752,1:TRAP 40000
920 IF ND<1 THEN 910
930 ? "{DOWN}AT THE CURRENT CONSUMPTION, YOU SHOULD"
940 IF DF<0 THEN PRINT "LOSE ";:GOTO 960
950 ? "GAIN ";
960 PRINT INT(ABS(DF*ND)/3500);" POUNDS."
970 END 
980 ? "? (Y/N):";
990 GET #1,A:A$=CHR$(A):IF A$<>"Y" AND A$<>"N" THEN 990
1000 YES=0:IF A$="N" THEN PRINT "NO":RETURN 
1010 YES=1:? "YES":RETURN 
1020 PRINT "{CLEAR}";
1030 ? "  {3 N}{3 SPACES}{2 N}{3 SPACES}{N}{5 SPACES}{3 N}{3 SPACES}{2 N}{3 SPACES}{N}{4 SPACES}{3 N}"
1040 ? " {F}{G}  {G} {F}{G} {G} {B}{2 G}{3 SPACES}{F}{G}  {G} {F}{G} {G} {B}{2 G}  {F}{G}  {G}"
1050 ? "{B}{G}{H}{3 SPACES}{B}{G}{H}  {J}{B}    {B}{G}{H}{3 SPACES}{B}{G}{H}  {J}{B}   {B}{G}{H}{3 SPACES}"
1060 ? "{B}  {3 SPACES}{B}  {N}{V} {B}    {B}  {3 SPACES}{B}  {N}{V} {B}   {B}  "
1070 ? "{B}  {3 SPACES}{B}   {G} {B}    {B}  {3 SPACES}{B}   {G} {B}   {B}  "
1080 ? " {G} {2 M}{G}{B} {4 SPACES}{B}  {M}{G} {G} {2 M}{G}{B} {4 SPACES}{B}  {M}{2 G} {2 M}{G}"
1090 ? "  {J}{3 SPACES} {G}  {G}  {G}{3 SPACES}  {J}{3 SPACES} {G}  {G}  {G}{3 SPACES} {J}{3 SPACES}"
1110 ? :POKE 85,11:? "CALORIE CALCULATOR"
1120 PRINT "{40 R}"
1130 RETURN 
1140 DATA CHEDDAR CHEESE,113,1'' CUBE
1150 DATA COTTAGE CHEESE, 27, 1 OZ
1160 DATA WHOLE MILK,166,1 CUP
1170 DATA NONFAT MILK,87,1 CUP
1180 DATA GRAPEFRUIT,77,1 CUP
1190 DATA ORANGES,70,1 MED.
1200 DATA CANTALOUPES,37,1/2 MELON
1210 DATA APPLES,87,1 MED.
1220 DATA ORANGE JUICE,108,1 CUP
1230 DATA CORN FLAKES,96,1 CUP
1240 DATA WHITE BREAD,63,1 SLICE
1250 DATA WHOLE WHEAT BREAD,55,1 SLICE
1260 DATA HAMBURGER MEAT,316,3 OZ.
1270 DATA STEAK,293,3 OZ.
1280 DATA LAMB CHOP,480,4 OZ.
1290 DATA BACON,48,1 SLICE
1300 DATA HAM,340,3 OZ.
1310 DATA FLOUNDER,78,4 OZ.
1320 DATA TUNA FISH,170,3 OZ.
1330 DATA CHICKEN,227,4 OZ.
1340 DATA EGGS,640,1 CUP
1350 DATA SUGAR,48,1 TBS.
1360 DATA CARROTS,68,1 CUP
1370 DATA POTATOES,120,1 MED.
1380 DATA BEET GREENS,39,1 CUP
1390 DATA LETTUCE,7,4 SM. LEAVES
1400 DATA SPINACH,46,1 CUP
1410 DATA BAKED BEANS,295,1 CUP
1420 DATA LIMA BEANS,152,1 CUP
1430 DATA CORN,92,8'' EAR
1440 DATA PEAS,74,.5 CUP
1450 DATA TOMATOES,30,1 MED.
1460 DATA 4% BEER,150,12 OZ.
1470 DATA BLACK COFFEE,9,1 CUP
1480 DATA COLA BEVERAGES,83,6 OZ.
1490 DATA POTATO CHIPS,108,10 2'' CHIPS
1500 DATA END,0,0
There are a couple of logic errors in this code:

  1. line 770:
    770 IF AGE>=20 OR AGE<30 THEN CPD=3200:IF SX THEN CPD=2300
    This sets the CPD variable no matter what age was entered because every number is >=20 or <30! The line should read:
    770 IF AGE>=20 and AGE<30 THEN CPD=3200:IF SX THEN CPD=2300

  2. lines 780 through 800:
    Notice something missing? What if the user is exactly age 30, 40, or 60? In this case, the program's incorrect logic on line 770 will set the CPD (even though it wouldn't be appropriate). The lines of code should include a >= instead of just a >, as shown here:
    780 IF AGE>=30 AND AGE<40 THEN CPD=3104:IF SX THEN CPD=2231
    790 IF AGE>=40 AND AGE<60 THEN CPD=2768:IF SX THEN CPD=1990
    800 IF AGE>=60 AND AGE<70 THEN CPD=2528:IF SX THEN CPD=1587
    

These lines have not been fixed in the listing above or below, it is simply being pointed out.

Listing. CalCalc.
Download (Saved BASIC) / Download (Listed BASIC)


Return to Table of Contents | Previous Section | Next Section