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

Section 1 - What is a Program?

It is suggested that before we start to write and save programs, we should create a directory into which to put them. To do this key LS(hold) UPDIR to get to the Home directory. Now key LS FILES F6-OK NXT F3-NEW DA. Type in your choice of name for the new directory, then DA F3-CHK F6-OK. Finally, press CANCEL (the ON button) to get out of the FILE dialog box. Now press VAR and press the soft menu key for the new directory you just created (it should be F1.) You are now in your new directory and ready to start saving new programs in it. For more about directories and saving variables see UG 2-32 to 2-59.

Basically, an HP49G+ program is an object that contains a listing of the steps to solve a particular type of problem. Let us look at a simple example. In a typical bowling league each member of each team bowls three games in a match. To find the average for a particular member for the match, you must add the individual's three scores and divide by 3. If the three scores were on the stack of your HP49G+, you would push the plus sign twice, enter a 3, and push the division key. Let us make this a program. On the HP49G+ the listing of a program must be enclosed in the symbols << >>, which is a right shifted plus sign. Our program then, would be

Type the above program into the command line by keying

RS <<>> + + 3

then press ENTER to put it on level 1 of the stack. Notice that as soon as you press RS << >>, you see the PRG annunciator in the upper right corner of the display, telling you that the calculator is in program mode. Also notice that division is shown as "/" in the program. For a program to be useful, it must be given a name and saved. Let us call it BWL1. Type 'BWL1' into the command line and press STO. If you now press VAR you should see BWL1 as the first item in your menu. To run the program put three scores on the stack and press the soft key for BWL1. Try it with the scores 172, 188, and 186: put the three numbers on stack levels 1, 2 and 3, then press the BWL1 menu key. You should see 182 on level 1 of the stack. (NOTE: The last number in the previous example could, alternatively, have been left in the command line; as in most HP49G+ operations.)

The program above is short enough to fit in one line on the screen, but that will not always be the case. When entering longer programs it is helpful to use the carriage return, (right shift decimal point) to go to a new line while in program mode. This also serves as a carriage return in a string. Recall that in the HP language a string is any group of characters surrounded by quotation marks.

EXERCISE SET 1

1. Write a program called TAX1 to find a six percent sales tax for the amount in level 1 of the stack. HINT: If you have the program set the number format to Fix 2 the tax will be shown rounded to the nearest penny. To do this include the sequence

2 LS PRG NXT F4-MODES F1-FMT F2-FIX

at the beginning of the program. All you will see in the program is "2 FIX."

2. Your sales force works 5 days per week. Each person's pay for the week is $500 plus 5% of sales over $1000. For example: a salesperson who sells $1200 in the week would earn $500 plus 5% of $200, which is $510. Write a program called PAY to take the five daily sales figures from the stack and compute the person's pay for the week. WARNING: Be sure you do not penalize a person who sells less than $1000 for the week. The MAX function (LS MTH F5-REAL F5-MAX) should be helpful here. Function MAX is explained on page 3-13 of UG.

3. In Pennsylvania (as in many other states) the exits on the interstate highways are numbered by the nearest mile marker, and the speed limit is 65 MPH. Write a program called TMR1 to take the exit number and the mile marker you just passed from the stack and compute the time it will take you to reach the exit assuming you are traveling at 65 MPH. NOTE: The ABS function (left shifted division key) should be useful to make sure you don't end up with a negative time. Function (LS PRG NXT NXT F1-TIME NXT ), which is explained on page 25-3 of UG may also be helpful here. Since an answer to the nearest minute would normally be good enough for this type of problem, it would also make sense to set the display to FIX 2 for this program.

Cover Page
Table of Contents
Index
Top of Page
Next Section