Previous Section
Cover Page
Table of Contents
Index
Exercises for this Section
Next Section

Section 7 - Flags

The HP49G+ has 256 user flags (numbered 1 to 256) that can be thought of as built in boolean variables. LS PRG F4-TEST NXT NXT will take you to a menu with six flag commands; SF = set flag, CF = clear flag, FS? = is flag set?, FC? = is flag clear?, FS?C = is flag set and clear it, and FC?C = is flag clear and clear it. To use any of the commands a flag number must be on level 1 of the stack. When the command is executed, the number is removed from the stack, and in the case of the last four commands, the appropriate response, 1 for yes or true and 0 for no or false, is placed on level 1. For more details on these commands see Chapter 24 of UG.

Suppose our bowling league is for families with children and the kids get a little extra handicap depending on their ages: those at least 10 but less than 13 get an extra 5 pins, those at least 7 but less than 10 get an extra 10 pins, and those less than 7 get an extra 15 pins. We will rewrite BWL4 to incorporate these new rules and call it BWL6. Run it with different choices for the ages of the bowler to see how it works.

	<<
	   "Is the bowler less  than 13? Y/N" {  "" } INPUT
	   IF "Y" == THEN
	      "Enter age group: 
	      "
	      "" INPUT  SF
	   END
	   "GAME 1 SCORE" "" INPUT 
	   "GAME 2 SCORE" "" INPUT 
	   "GAME 3 SCORE" "" INPUT 
	   0 0 0  s1 s2 s3 tot avrg hncp
	   <<
	      s1 s2 + s3 + 'tot' STO
	      tot 3 / FLOOR 'avrg' STO
	      200 avrg - 0 MAX .8 * FLOOR
	      CASE
	         1 FS?C THEN 5 + END
	         2 FS?C THEN 10 + END
	         3 FS?C THEN 15 + END
	      END
	      'hncp' STO
	      tot "TOTAL" 
	      avrg "AVERAGE" 
	      hncp "HANDICAP" 
	   >>
	>>

Notice that the program will leave no flags set when it ends. It is wise to make sure that any program that uses flags leaves them all clear at the end. If there are several flags to clear at once, their numbers can be put in a list on level 1 of the stack, the CF will clear them all.

EXERCISE SET 7

1. Change Problem 3 of Exercise Set 5 as follows: If the employee is over 62 or disabled, the withholdings are reduced by 10% of the initial calculation; if the employee is both over 62 and disabled, the withholdings are reduced by 15% of the initial calculation. Be sure to make appropriate use of flags. Save this program as NPAY2.

Previous Section
Cover Page
Table of Contents
Index
Top of Page
Next Section