Manual / Guide · c. 1983
Tandy Model PC-4 Pocket Computer Programming Guide
The programming guide for the Tandy PC-4, Radio Shack's version of the Casio PB-100.
Manual / Guide · c. 1983
The programming guide for the Tandy PC-4, Radio Shack's version of the Casio PB-100.
Radie Shaek Miodel PC -44 Programming Guide Introduction to Computing With TRS-8SO Pocket Computer Model PC-4 @ Step-by-Step Instructions @ Programs for Statistics, Games, Finance And More! Cat. No. 26-3650 PREFACE Today personal computers can be seen wherever you go. They are in wide use as tools for both business and research. As a result, software is becoming more and more important. BASIC, a language used for personal computers, can be under- stood by everyone, because it uses words found in everyday colversation. BASIC is the first step in making various kinds of work more efficient. Consequently, more and more people in various fields are becoming interested and BASIC is gaining wider recognition, But at the same time, there seems to be an increasing number of people who shy away from BASIC because they think it is dif- ficult to learn. When it comes to BASIC programming, as in many other things, “practice makes perfect”, However, many people who would like to learn it are having difficulty finding the time and place to do so, This manual and the PC-4 have been designed for use at almost any time or location, The manual is written in a clear, easy-to- follow format. We feel that you will enjoy learning from it while actually practicing various programming techniques with the PC-4 Personal Computer. Short programs are used to pro- vide ample opportunity for improving your skill. This manual places emphasis on gaining practical experience. That’s why in the very first chapter the question “What can I use the PC-4 for?” is asked and answered. Even without knowing the grammar, you can input short programs and try to execute them. BASIC grammar is written in easily understandable terms that anyone, given some practice, can comprehend. Interesting examples have been included in the program library, These have been developed with the assistance of noted authorities in the computer field. By making your own modifications, you will be able to find out just what can be done using BASIC, all the while becoming more and more skillful. By using this manual, soon every member of the family will become a BASIC fan. Chapter 1 What Is the PC-4 Used for ? 1.1 Learning BASIC by using the PC~4 ek RK 8 1.2 What do we use the PC-4 for ? tek ER 10 1.3 I want to master BASIC! RASS 11 1.4 I want to play a game ! Ok Ree 15 1.5 JT want to use it for accounting or business applications ! SKK oe ok 19 1.6 IT want co use it for statistics or prediction calculation ! ek ak ok 23 1.7 I want to use the PC-4 for data management or arrangement ! ee 26 1.8 I want to use it as a notebook ! OK km 31 Chapter 2 What Is a Program ? 2.1 The Radio Shack PC-4,a pocketable computer and calculator in a single unit hee 36 2.2 There are no scientific function keys on the PC-4 but don’t worry. RR He 40 2.3 Obtaining the coral of the numbers 1 through 10 ae eek ae 42 2.4 Simultaneous calculation of sum and square sum OR OR 47 Chapter3 This Is a Program ! 3.1 Programming at last! Bok kk me 52 3.2 Program to obtain the total of the numbers 1 through 10 RRR Re 54 3.3. A slight change in the program Kk RR ® 59 3.4 Program to obtain the square sum simultane- ously Hk 61 3.5 Program for obtaining the sum of optional numbers ie 64 3.6 A slight change in the program RR AR 67 3.7 Conclusion SRR oe oe 69 Now Let’s Learn BASIC. 4.1 BASIC and the PC -4 Re ke 72 4.2. Commands required to perform addition, subtraction, multiplication, and division Re KOR & 73 4.3 Repeating any number of times eo ok ak ok 79 4.4 Which one is the largest ? AK ae 84 4.5 Challenging the troublesome deviation values & KK 88 4.6 Obtaining separate rotals Fe 94 4.7 Another type of variable—array variables BORO a 99 4.8 Jump !—GOTO OR eo ok 104 4.9 Frequently ~made errors eee LOT 4.10 The game's leading players—random numbers # * * # x 109 4.11 The ABC’s of games ee ee ee 4.12 Dice game KR 114 4.13 Line up! SRR LG 4.14 Sorting of names as well ok RR 128 4.15 Character variables also have sizes. eke 127 4.16 Find the data! — 1. wee 130 4.17 Find the data! — 2. KOK RR 139 4.18 Roulette is also useful for mathematics ! KKK 144 4.19 Let’s use the PC-4 to play che “paper~ scissors~ rock” game, wR EK LS] Chapter5 Program Library Cassette tape recording plan wR HR 158 Vertical and horizontal coral. ke RR GO Scheduler kak 168 Telephone list waka 166 Train cimetable eA 1G9 Golf game wake Se 17D Slot game eeeee 174 Standard deviation and statistics wwe 176 Regression analysis ee RRR 179 Annual average growth rate eek RR 182 Decimal ¢emp base-n conversion ROR CE 184 Least common multiple and greatest common measure eek 8H Prime factorization woke TBR Universal power calculation KR 190 Simultaneous linear equations Bee LOR Function List wee ee 195 Chapter 1 _ What Is the PC-4 Used for ? 1.1 Learning BASIC by using the PC-4 The computer has now advanced to a level where it is used not only by experts but also by grammar school students. As a result of the progress made in semi-conductor tech- nology, the computer has entered an age when it can be made smaller and smaller. At first glance, the PC-4 looks like a calculator with a lot more keys. Personal computers, which can be placed ona table, are talked about as being the standard of the microcom- puter age. On the other hand, the PC-4 is a “pocketable com- puter”. This does not mean however that the PC-4 is just an oversized calculator. On the contrary, it is a genuine computer in every respect. This is because the PC-4 uses a high-level programming language known as BASIC and that can be used to perform a wide range of tasks. BASIC is a language which is used in the small business field or in technological applications. It is not a difficult language to learn. Even grammar school students can use it after some training. A high-level language means that we can program using words which are similar to those used in daily conversa- tion, rather than very special computer codes. Of course, you cannot become a programming expert with only two or three days of study. However, if you try the program examples in this manual, one by one, you will naturally gain a better understanding of BASIC. As will be stated over and over in this manual, when it ae Learning BASIC by using the PC-4 comes to programming, doing is more important than reading. So follow the examples and press the keys. An “ERR” (ERROR) display may appear often, but, if you try to figure out the cause, you will slowly gain an understanding of the various operations. This manual has been written so that you can refer to specific pages for guidance whenever you have dif- ficulty. So let’s relax and learn BASIC. 1.2 What do we use the PC-4 for “PC-4 Application Map” ? 1.3 I want to master BASIC! The PC-4 is a splendid device for beginning the study of BASIC, One reason for this is that the BASIC which is used in the PC-4 is very close to standard BASIC (the internal circuitry is standard). The following program is a short but typical example of BASIC. Aimost all personal computers can run it. This program includes a fundamental loop and a sub- stitution statement. Using the BASIC learned with the PC-4 you can take on larger computers when you have to. Chapter 1 What Is the PC-4 Used for? For those who would like to master BASIC, input the program shown below using the operating procedure. This is a program to obtain the total of numbers from 1 through N For example, if 10 is input for N, the result will be 55. Program to obtain the total of numbers from 1 through N nia? Kad Pog pete WR aon [Program input procedure] Power ON [Explanation] This Program contains fundamental BASIC commands. If you can understand this program, it means that you have mastered the funda- mentals of BASIC. The meanings of the commands and symbols which are used here are explained in Chapters 2 through 4. After trying this program out by inputting vari- ous numbers for N, refer to Chapter 2 for a more through explanation. <1 QUE AR A Exe) The display will read as follows. co Means that a pragram can be written. (Ornitted hereafter) f ¥ [ WRT OEG P@123456789 “™ Blinks (Reacly for writing in P@} <2> Display at this time 10 INPUT "N= cent 7.3. | want to master BASIC! fracel 'S) is the Shift Key. Do not confuse it with the regular letter (S), ao BUS8088 Confirm the display. Does it read as follows? oP) i [) 20 o> BOOoOSMOhco (N) (EXE so AOS HWE <a> (5) (@) S) Can OD EXE m OOS 5 S) BE AOS 5 WO OGE This completes the input. You should have confirmed the display for operations <4 > through < 8 > as well. If a mistake is made during the above operation, press (47) and to move the blinking dash (cursor) to the position you want to correct and reinput the correct information. [Program execution procedure] (1) After the Key is pressed for operation <8 > above, press {S) ,%) and the display will be as follows, g (Pp 123456789 (2) (MODE) [2] 1.4 I want to play a game! There are probably a lot of people who would like to use the PC-4 to play games. There is no reason why you can’t enjoy yourself and learn BASIC at the same time. With the PC-4, there is no capability to have large ob- jects jumping around on the screen because the display is rather small. Nevertheless, there are numerous mental games which can be enjoyed using the PC-4. Several of these are contained in this manual. If programs are recorded on a cassette tape using your tape recorder, you can enjoy various games at any time by calling out the programs from the tape. Well, let’s play. HI-LO Game [Explanation] At the beginning of the game, the PC-4 hides a number. The object of the game is for you to guess what the number might be. When you venture some number using the numerical keys, the PC-4 will display whether the number you guessed is higher than (“HI:K=”) or lower than (“LO:K=”) the hidden num- ber. By repeating this cycle, you can get closer and closer to the hidden number. How good is your sixth sense? Chapter 1 What Is the PC-4 Used for? eect os tennene For those people, who say “I want to play a game.”, input this program into the PC-4 by using the following procedure. This game is called the “number guessing game” or the “HI-LOW game”’. See how many turns it takes to guess the number. This game can be enjoyed by two or more people. HI-LO Game program Pa i@ PRINT "HI-Lg" 38 PRINT "GOOD: ANS 28 KSA INPUT "KEY ="SREPRINT "K=* TN LENGTH "54 Ki G0T0 28 R=INT CRANHLBt 14 4f INPUT "KEY IN G." ArksK+lsH$= are ad TF A=R THEN 26 od IF ACRSH$="LG" TS PRINT H$s*tk="5 KiG0TO 48 [Program input procedure] Power ON <1> (MODE) (1) (c) &) (E) A) (R) () Exe) Display at this time WRT DEG | Omieted hereatter ) PQ@123456789 | L Blinks OW 0) S) wm Ex Display at this time f 10, PRINT "HI ! want to play a game! oe NG nw - v ) Key for the last time, corrections can be made by moving the cursor to the desired position using the Airection keys ( (=) “INPUT EXE) a) Prior to. pressing the Display at this time : BR @ ae 985 ee I) Jqdae8 so 2 Be, 3 0G 2 eae et on 8 {a} (<] - ale SMEG HE (et 2 2980) om. 28. ,8og — aM) esses ee & S CR o, 8 = o "gS as Ss = EXE 5} 7 4 } anal Letce oe A} ele C ui (N): <B> <9> ira Chapter 1 What Is the PC-4 Used for? . i SaGBSunGass wh Ow oo W This completes the input. [Program execution procedure] (1) After pressing the EXE) Key for <9> above, press [<5] (6) and the display will be as follows. 5 P123456789 | (2) The display will be as follows. RUN DEG READY P@ (3) Press (Sir). Does the display show HI-LO? If So, press the Key and KEY IN LENGTH? will be displayed. This is asking you “How many digits do you want in the number to be guessed?”. You can designate a number such as 1 through 10; if you press , the hidden number will be 0 through 99, and if you Press » the number will be 0 through 999. Here, press , then KEY IN NO? is displayed and the game begins. If a number from 0 through 99 is input followed by {EXE}, the display will read LO:K=1 or HI:K=1, LO means too low and HI means too high. K is the number of guesses. Since KEY IN NO.? is displayed again by pressing EXE] , input an appropriate number. By repeating this, you can get closer and closer to the hidden number. When you succeed, GOOD: ANS=00 (hidden number) is displayed, and K=00 (number of trials) is given by pressing . 1.5 | want to use it for accounting or business applications ! You probably realize that computers are used in today’s society for performing a variety of functions. The out- standing feature of a computer is its ability to handle and process many calculations. An endless number of business applications, such as sales accounting, stock control, calculation of loan payments, making estimates and cost accounting, can be performed more efficiently with the aid of a computer. The PC-4 can perform all of these functions with few limitations. We will use the calculation of loan payments as an example. With it, you can determine the proper periodic payment and surprise the salesman. Calculation of monthly loan payment Suppose you are buying a new automobile and the sales price is $10,000 with an annual interest rate of 11% and 24 monthly payments. In this case, what is the monthly payment when the down payment was $1,000, $2,000, etc.? The calculation is performed using the following for- mula. can P: Monthly payment P=(PT-~ R)X—-———- ween — PT: Price i R: Down payment 1 “TT + §)F 0 Number of payments 12 i: Interest (annual rate) For P, the payment is rounded up to the nearest dollar. Chapter 1 What Is the PC-4 Used for? ores ne 20 There are probably a lot of people who will say, “I want to use the PC-4 for accounting or business applications.” Monthly loan payment calculations such as this, where a certain formula is used, can be done using a scientific calculator. However, using BASIC, anyone can obtain the result quickly and easily. Program for monthly loan payment [Explanation] of The calculation can be made with : i@ INPUT "PRICE", a such a short program. The X on line 28 TNPUIT "BHNUAL t 6@ is the numerator and the Y on RE line 7Q is the denominator. X/Y is ee) calculated on line 8@ and the result HPUT "HUMBER @ is rounded up to the nearest dollar. AYMENTS?.H The PC-4 will request the price, SQ INPUT "BOWN PAT annual interest, number of pay- ments and down payment. All you have to do is input the numbers. MT MONTHLY HT="3 180 8070 30 [Program input proceduure] > MOHDNCOOEARWEES 5 Display will show * * & VAR? 26 <2> Pas os —7 Bae o BO Sey “M. Oe ‘wENNUBOSIM NOERE aia cm_(MODE} (+) ©) & <4> Oa 1.5 ! want to use it for accounting or business applications! EX FO PATIENTS! © wf BIE o HOC OF wmOOWNSEIRAYM <7> (6) (a) K) wy & <8> OW 69> a> OBS egx MAHO)W) Pc RPAMMENT S &) ww (S) cw [kK] (EXE Mp | CH5 6) () EXE This completes program input. [Program execution procedurel (1) After pressing at step <11 > above, press (MODE) (@) & 1} and the display will be as follows. PRICE ? {2} Input 10000 and press EXE) and the display will be as follows. ANNUAL INTEREST(%)? (3) Hereafter, input the numbers following the display. Input 11 and press EX£) and the display will be as follows. NUMBER OF PAYMENTS ? Chapter 1 What Is the PC-4 Used for? 22 (4) Input 24 and press and the display will be as follows. DOWN PAYMENT ? (5) Input 1600 and press and the result will be as follows. MONTHLY PAYMENT = 420. (6) If you press , the program will return to Step <4>. This time, input 2000 and press and the result, $373, will be displayed. This can be repeated using various amounts. 1.6 I want to use it for statistics or prediction calculation ! The library section of this manual has examples of deviation value calculations and statistical calculations with two variables. These apply to the totaling and analysis of scores, to data analysis for quality control, and to prediction based on sampling. When you would like to know, for instance, the trend of a value which has a certain tendency, you can find it out using the moving average. For example, the stock prices on the stock market are changing daily. However, if you look at them at weekly or monthly intervals, you will see that they are going up or coming down. If you obtain the moving average, it is possible to predict the timing with which the stock market rises and falls. ; An example of prediction based on sampling is shown below. Product sales and production planning For many products, there is a seasonal variation. So let’s predict the proper production quantity for six months from now using the moving average value for past sales statistics. The past statistics are as follows. Month | Apr. | Sales quanti | of product A S49 | 248 | 411 | 857 | 192 | 235 | 480 | 331 | 928 | 459 | 366 | 529 | peti con a 451.4]388.6) 435 | 419 |433 2/486 6/512.8/522 6 2a Chapter 1 What Is the PC-4 Used for? For those who wonder, “What can be done using statistical or prediction calculations?”, try the following example. A 5- month moving average was obtained from the past year’s data. Using an 8-month moving average, let’s make a chart to predict 6 months into the future. Program to obtain the moving average ft <4) <5> <6> <7> <8> [Program input procedure] “> (MODE) MOO) RAEXE Se) EXE _ Display at this time. a aa xe V AR I47 [ BsA Baar C=f+ . (Data (nut mernory has bear Jasignatach} 3070 18 62> @ 2 Baal ex | ow NUMBOR) ) S) i U Q S of j qao0Be Sigacigicicig ~— 4.6 | want to use it for statistics or prediction calculation! 4 <g> aaosoen to) (A) EXE Oo YOOSBOAA Sm (E) ) w EXE <I> oe ice ee DiGiolace wo HAEOIHBEaS jaRDAOA I ooOe wo EXE (3) @) oO) cas @) @ Exe This completes program input, [Program execution procedure] (1) After pressing at step <14 > above, press (MODE) (@} (S) my and the display will be as follows. NUMBER OF MOVES=? (2) Since we are using a 5-month moving average, press (5} (€xXe} and the display will be as follows. DATA 1? (3) Input the sales quantity for the month of April which is given in the example. {9} (4) If you repeat this input up to August, the display will be as follows, AVERAGE =451.4 (5) After checking the result, press (XE) and the computer will ask what the next data is. (6) Hereafter, if you input data, the average for the preceding 5-month period will be displayed. If these average values are linked, the entire trend pattern can be plotted and observed. By extending the trend line formed by linking the average values, the target product quantity can be predicted, 1.7 I want to use the PC-4 for data management or arrangement ! 26 Suppose we have 7 products from A through G and the prices are as follows. A= $30 D=$250 F=$80 B=$180 E=$90 G=$130 C= $170 We can determine the weekly sales ranking for these products and arrange the figures in descending order. In other words, this is work where data is input and, ata certain point, a computation is performed to evaluate the data and to arrange it. This operation is very similar to Multiple Item Sales Ranking which is often per- formed in business. Now let’s process the above example using BASIC. Sales ranking of different products A | B c Oo E | F $ 30) $180) $170} $250] $901 $ go “week of September 18 6 aa Ts ah | It is more practical to accumulate the monthly sales for each product by lining the data up vertically. For beginners, however, we will use a simple example. With BASIC we will calculate the sales for each product from A through G and also rank them in descending order. cmon AT / want to use the PC-4 for data management or arrangement! This is an example for those who say, “I want to use it for data management and arrangement.”’ Managing and arranging can make data “‘come alive’ and be more meaningful.Do not simply rely on your feelings.BASIC gives you the power to compute and analyze. Sales ranking program 28 AtH+L 38 INPUT ITEM". EF F Hl A aziltl vaZcCeid LIB D=260}: 2603=260 FELD HL os 128 DSECCH9H 2040 HaZiCe deze C+14)=):B=1 138 NEXT C 40 TF E=1 THEN 78 £56 FOR C= TO At i6@ IF E$(0)=7872EN B 178 PRINT ES(0). "AM OUNT="5 ZiC+17) [Se PRINT "$7:7(C)4 ZiC+13) [Explanation] Let’s challenge a program which is a little longer. It is important that you press the keys correctly while inputting the program. Relax and take your time. If an error indication (ERR2 POQ- Line Number) is displayed during program execution({RUN), perform the following correction routine operation, (QS) cx line num- ber EXE} The program will be displayed. Move the cursor to the desired location using the direction keys ( and } and input the correct information, then press the Key. «~~ Note © Program correction (1) To delete one character, per- form the above operation then press the (delete} Key. (2) To insert one character, make an open space by pressing — Seo. : (3) To change information on a whole line, press line number we Be . Previous informa- tion on the line is erased and new information will be stored. To delete a whole line, press line number EXE}. 27 Chapter 1 What Is the PC-4 Used for? 28 [Program input procedure] @ The key symbol (( }) will be omitted except where required for special operations. <1> MODE] 1 CLEARA EXE] S) CX 25 EXE The display will be as follows. *RVAR 51 <2> 10 VAC <3> 20 A=A+1 Exe > 30S Cw ale) ITEM Simo) E Sid Sena GI EXE) <5> Sich & © Gc & Sica = S} w 0 [S) mw S)cey 70 Exe) <6> 50 S) OM SS) So UNIT PRICE= [S] wa SlhaZo maw S&S wy AM OUNT = (ww GS) ZS) em At+13 oS <7> 60S) CH 20 (EXE <8> 70 B= 0 69> 80 [Si (s} C=1 [5] ) A-2 BO <> §=©90 (S) cy 78meoGu* 728 mo 0+13 G) eal mz (SS) aq C+1 Oo* Zoom 0+4 aS ce 130 (EXE) (> 1000 Shay =EO am GM Hc alot Samm c Gm =e Sl S) ey c+1 Sica GS) me S) es S) a c+ So = = DS} cn Exe) <12> 11 joo-zOme Suimz © ace Sm =z Shea c+1 Oy & aa a iG <13> <14> <15> <16> <17> <18> <19> <20> 1.7 | want to use the PC-4 for data management or arrangernent! ZS) mo+1 Gm =) Be 120D= ZS enc+3GmaGinz emo chZ@ne+ 14S) = DS) cm B=1 Exe 130 - Sc S) C5 70 G=1 (5) i) A-1 JaSimcSma= in Oe eNOS OS) CLOSES mS) cc Sie’) eS) wm AMOUNT =o wi) ©) Zi) mct+i3 me e) 180 ASS dS) ws) eZ SlaacSieg * ZS) mH ot13 © oe 190 () a5 {Program execution procedure] a \ we pres Exe Ejat step < 20 > above, press TEM ? (2) Product A in the example is input by pressing (A) EXE}. The display will be as follows. UNIT PRICE=? (3) Press (3) (@) EXE). The display will be as follows. AMOUNT = ? (4) Press (7) (8) EXE!. The display will be as follows. ITEM ? Input data by repeating steps (2) through (4). 29 Chapter 1 What Is the PC-4 Used for? 30 (5) After inputting 5 as the amount for product G, if keys are pressed in response to ITEM?, the data will be sorted internally and the item with the highest sales value will be displayed, in this case, F. If is pressed again, the display will be as follows. AMOUNT = 20 If is pressed again, the display will be as follows $1,600 Heréafter, if you keep pressing , the display will show the other data in descending order. 1.8 | want to use it as a notebook! Refer to the part of the library section entitled “Scheduler”. The PC-4 can be used as a notebook by storing a schedule, calling it out, and adding or deleting as needed. A maximum of 22 items can be stored. If a RAM Expansion Pack (optional equipment) is added, this can be increased to 150 items. The 26 Keys from A through Z become the drawers of the memory and you can store the desired contents in them. When more than 26 drawers are required, press The display will be as follows. DEFM If you want to make 25 more drawers, press the following Keys. The display will be as follows. * * EVAR: 51 This means you now have 51 drawers in which to store items. The cv} Key plays an active role when using the PC-4 as a notebook. SCHEDULE ON MAY 10 10:10 MEETING 10:30 FISHING 12:00 LUNCH 18:00 RECEPTION BASIC is splendid for handling characters. 31 Chapter 1 What Is the PC-4 Used for? mee 32 For those who want to use the PC-4 as a notebook, try the following program. This is a program for inputting items and prices one after another. Then fater, the amount and pricing data for a certain item can be called out. This is also a con- venient program to register those in attendance at a certain event, such as charity concerts, charity bazaars, etc. Program for items and prices [Explanation] Pa The PC-4 permits storage of 10 dif- if IN ferent programs in program areas P@ through P9, This allows one program to be divided and stored in three different areas for individual purposes. For example, the data may be input into P9, called out using PQ, and totalled using P1: [Program input procedure] The key symbol ([{_)} will be omitted except where required for special operations. < Input to Pg > sa PpINT “ToTH=; <1? (MODE) 1CLEARA oA 23 2@ FOR §=1 70 23 The display at this time will be as 78 INPUT "ITEW", Ds follows. 48 INPUT "PRICE", 2 ***V AR 249 58 WEST & <2> 10 VAC ED ~~ 1.8 | want to use jt as a notebook! <input to PQ > 10) ew ITEM (=) <2> <3> <4> <5> | NO NAME | 068 <6> <7> <8> <input to Pi > 20 Bg Bat ~° ©) ae <2> 63> 64> 68> 80) ce | oo (a) C (EXE) 33 Chapter 1 What Is the PC-4 Used for? 34 [Program execution procedure] (1) Press ©9 (and the display will be as follows. ITEM ? (2) For example, input HOLMES and press EXE) and the display will be as follows. PRICE ? (3) For example, input 20 and press and the display will be as follows. ITEM ? Input various names and prices one after another. A total of up to 23 names and prices can be input. (4) For example, if you want to know the data for HOLMES, press |“! (@) (H) (0) and the price will be displayed. Also, the total can be ob- tained by pressing =) (35- What Is a Program ? 2.1 The Radio Shack PC-4, a pocketable computer and calculator in a single unit Wel, let's begin. READY Po The words “program” or “programming” are usually associated with computers. But what exactly is a pro- gram? Simply, a program is a set of instructions telling a computer what to do. For those studying program- ming for the first time, we will discuss how to think in terms of the program language BASIC. This does not mean that we will be speaking about something which is very difficult to understand, so just relax and read on. First, let’s take a look at the Radio Shack PC-4 and how it operates. The PC-4 is a real computer but may also be used as a calculator. First, turn the Power Switch on. RUN DEG H i i } J 36 The display on the PC-4 will appear as shown above. Press the following keys in sequence. It will take a moment to locate the positions of the keys at first but,after using the PC-4 for a while, you will be able to find them quickly. The Exe! Key is located on the lower right side of the PC-4. EXE is short for EXECUTE and it acts like an equals sign (=) Key on an ordinary calculator. 21 The Radio Shack PC-4, a pocketable computer and calculator in a single unit You should get a result of 8 after you press this key. Those who are used to performing addition on a cal- culator may consider this procedure a little strange at first. That’s because when using a standard calculator the operation is completed by pressing the following keys. If you try to perform the operation in the PC-4 by using this sequence, you will get a blinking ‘‘—” (This is called the “‘cursor”’.) instead of an answer. The'= Key on the PC-4_ is only used during program- ming and has a different meaning. With the PC-4, the (EXg (Execute) Key is used instead of the (= Key for calculations. Don’t press (5, press (EXE) . By the way, a standard calculator has an (M+) Key (Memory Plus Key) and an (MR) Key (Memory Recall Key) to store numbers in the memory and to call out the memory contents. If you take a look at the PC-4 Keyboard, you will not find these Keys. You might think that the PC-4 has no memory. However the PC-4 is a powerful computer, with superior memory func- tions, when compared to a calculator, execute a com- mand or input data, Calculator men. ory aad PO. memory. 37 Chapter 2. What Is a Program? a progranmt, me- ies Ato 2 are called “‘variables. 38 For example, press the following Keys. (A) EXE) A number will appear on the display. That number is the contents stored in memory “A”. The above key operation simply calls out the contents of memory ‘‘A”’. Now press the following keys. 2) |EXE) Is there any display? This operation calls out the contents of memory “Z”. In this manner, you can see that there are 26 memories from A to Z in the PC-4. Numbers with a maximum of 12 digits can be stored in each memory and a maximum of 10 digits can be dis- played at one time. Memories A to Z are known as “‘variables” when they are used in programming. Letters A through 27 are memo- tes, also Rrown as variables , and numbers can be stored in them. You should re- member this. 27 The Radio Shack PC-4, a pocketable computer and calculator in a single unit These memory contents can be used for performing addition, subtraction, multiplication and division when they contain known numbers. For example, press the following keys. 1) @) EXE and (7) These operations store 10 in memory “A” and 2 in memory “Z”. Note the previously stored numbers have been replaced by 10 and 2. Now press the following keys. Alt The result should be 12. Next, press the following keys. What is the result now? It should be 8. Now let’s perform multiplication and division. If you look at the PC-4, you will see that there is no x or +) Key. Since the symbol for multiplication looks like the letter “X’’, an asterisk (%') symbol is used instead. Also, a '/\(slash) symbol is used for division instead of fe On the conventional ‘=" symbol. aor Now let’s try multiplication and division using the ee contents of memory “‘A’’ and memory “‘Z”’. As you may have guessed, the key operation is as fol- lows. getting used te operating the A) (Z) EXE Were the results 20 and 5 respectively? Incidentally, if you make a mistake and touch the wrong key, you don’t have to clear everything. Press the direc- tion keys (| <= jand| <5 )) and enter the correct number. 39 2.2 There are no scientific function keys on the PC-4 but don’t worry, 40 The PC-4 has 26 memories (from A to Z) and we have learned that we can use these when performing addition subtraction, multiplication and division. Now we will learn how to perform other functions such as sine, cosine and tangent. Some people might say, “I can do those kinds of calcu- lations quickly using a scientific calculator,” Scientific calculators have keys such as “sin. , ‘cos’ and tan). The PC-4 does not have these keys. Let’s try these function calculations using the PC-4. For example, obtain sin 30°. Key operation is as follows. ’ @ are keys to ex- press the angular unit of a number following SIN in degrees. The display shows DEG, doesn’t it? Since the display will show DEG when the PC-4 power switch /s turned on, this ope- ration may be omitted at that time. 2.2 There are no scjentitic function keys on the PC-4 but don’t worry You must pay attention to one point. With a function calculator, input is made as follows. But with the PC-4, the function is entered first. This is very important when programming so please remember this point. Now, let’s use the knowledge gained so far and use the memory contents instead of the number 30. Memory ‘“‘A’”’ now contains the number 10, doesn’t it? Press the following Keys. (S) LL) /N) Al EXE) The result should be 0.1736481777. As you know by now, the above is the method for obtaining sin 10°. From this you can see that the PC-4 not only performs all of the functions of a scientific calculator but also has abundant memory to facilitate those functions. These functions are just a small portion of the many capabilities of the PC-4, Read on and you will be convinced of this. Of course, | can ‘also be used as a function calcula- tor with memo- ries but | really have much more superiorcapabil- f itles, 4] 2.3 Obtaining the total of the numbers 1 through 10 42 We have already explained that the ability to perform scientific function calculations with abundant memory functions is only one of the many capabilities of the PC-4, Well, what other capabilities does the PC-4 have? It is capable of computing functions using a variety of programs, If you do not know much about programming, you might think this function is of no use to you. But by using a system of simple “manual programming”, you will slowly be led into the knowledge of program- ming computers. Now let’s obtain the cumulative totals of the numbers 1 through 10. Actually, if you are good at mathematics, you can get the answer pretty quickly on your own without using a computer but bear with us for a moment. ® The first method. The calculator approach. The above key operation is one method of obtaining the incremental totals of the numbers 1 through 10. This operation is almost the same as that used for a 23 Obtaining the total of the numbers 1 through 10 standard calculator. ® The second method. A bit closer to actual program- ming. Remember that the PC-4 has memories from “A” to ay Aan Using one of these memories, we can obtain the total in a different manner. Here we come a bit closer to thinking in terms of a program. Turn the power switch on. Since we will be using memory “'A”, clear it by pressing the following Keys. (Al =! (Q) EXE) This operation means “write @ to memory A” and the ‘EXE Key means “execute this operation.” The {AG} Key is used to clear everything To clear from the dis- memary “A”, play. When a press (A) ©} mistake has been f@) Exe. made in key Alsa, to clear operation, you all of the can press (KG) memories from and reinput the A through 2, press (¥) correct infor. mation trom the beginning. Now let’s check to see if the above operation stored a @ in memory “A”. Chapter 2 What Is a Program? The (2) symbol is different from the equal sign used in mathematics, I'm poor at mathe- matics! 44 Press the following Keys. A) (EXE) Is a Q displayed? Next, we will add the numbers 1 through 10 in sequence in memory “A”, First, to add in the number 1, press the following Keys. The equal symbol does not mean that the two sides of the equation are equal. It merely means “put the result of the operation on the right side of the ‘=| symbol into memory A”. The = symbol used here has a meaning which is different from the =! sign used in mathematics, Since it is easy to confuse the meaning of the = =| symbol, please be careful. Now let’s check the contents of memory “A” to see what it has become as a result of performing the above operation. Press the following Keys. A) |EXE) Is the result 1? In the same manner, repeat the operation the required number of times. A) 3a ne manner far 4 through 9.) 10 It was a bit lengthy, but did you get the correct answer? You must be careful not to omit anything and not to add the same number twice. Now let’s try a third method. 2.3 Obtaining the total of the numbers 1 through 10 © The thrid method. Even closer to actual program- ming. Since the PC-4 has 26 memories (from “A” to “Z”), let’s prepare another memory and see what numbers were just added. Since the numbers which were added to one another increase by 1 in sequence, we will store this in memory pe Clear memory ‘‘1”” in the same manner as “A” was cleared in the previous example. Press the following keys. Check to see if the operation was successful. Press the following keys. Is the result 1? Next, add the contents of memory “I”? to memory ay. Press the re Following _ We're get- - ting closer E " and closer ( to think- ; ing in fe terms of a. program. Chapter 2 What Is a Program? The entire operation is as follows. ‘A = 0 EXE LL) =) (0) (EXE) Repeat until 10, This is called a Clear “loop". | is increased by 1 and that amount is added to A, Comparison is H vot, made to : a ae determine j oe - i is equa : to 10 or When the value of } less than10. is less than 10, | When the value of I becomes 10. The result is displayed. 46 Using this operation me- thod, if the 'i) and € Keys are pressed along the way, you can check to see what number is being added at that point. If you take a look at the figure on the left, the Key operation which was listed above will be easier to understand. 2.4 Simultaneous calculation of sum and square sum In the previous examples, the total of the numbers from 1 through 10 was written in memory “A”. Now let’s extend the operation further and also write the square sum from 1 to 10 in memory “B”. In this manner, two jobs can be combined into a single sequence. This means that both of the following operations will be executed simultaneously. A#~ 14243... +10 Bom 17427437 0. + 10? ® The fourth method. We are now beginning to really resemble programming. . If this operation is performed using a calculator with an ordinary memory, A will be obtained first and B will be obtained last. However, if you use a method which resembles pro- poo gramming as shown below, A and B can be obtained \ Iseel J simultaneously. \ 47 Chapter 2. What Is a Program? . ose To find out the current step you are on during the above operation, simply press CL EXE) As with the third method, this operation will be easier to understand if you refer to the figure below. When computers were less functional and more expen- sive, procedures such as that shown below were time consuming and cumbersome. Clear fis increased by 1 each time, — : The |-which has seen increased is. added to A.and A becomes - anew value. Posoesan EXE Also, that bis squared and added i to B, and B becomes a-new value. When 1<10_ ° When | = 10 48 2.4 Simultaneous calculation of sum and square sum Also, the keying operation requires much patience. The “programming” approach enables us to put the entire procedure into the memory and simply plug in the desired numbers. ® The fifth method. Extremely close to programming. Now, let’s try just a little harder and expand the way of thinking even more. In the fourth method, the sum of the numbers 1 through 10 was obtained as well as the sum of the squares. Now we would like to obtain the sum of optional 10 numbers as well as the square sum. At this time, there is a new requirement to store the value of the optional numbers in a memory. Let’s use memory “X’’ for this purpose. Memories “A”, “B” and “Il” are used the same as before. Memory “I” is used to count the number of times the optional number values (called data) are input. If the input value (data) is labeled as Xi (i = 1, 2 sees 10), we get the fol- lowing. . A Xp + X24 ..4X10 B+ X? +X24..4X? As with the third and fourth methods, the en- tire procedure is as shown on the right. Try to operate the keys in accordance with the figure and input some actual data. | Makes it pos- ) ‘sible for optional) (data to be input. ) [BIExE] End } 49 Chapter 2. What fs a Program? 50 Thisisa bit tiring, . isn't it? By the way, this example is a very useful one. Suppose the data of X, through Xj are test results. The average score can be obtained in the following manner. In Chapter 4, Section 5, entitled ‘Challenging the troublesome deviation values”, will explain some useful applications for the square sum. Following is some sample data. Use it to obtain the average score. 30, 50, 80, 40, 20, 70, 60, 90, 50, 80 If the value of A becomes 570 and the value of B becomes 37300, the answer is correct and the average score will be 57. How did you make out? Did you make the inputs correctly? Was it difficult? The operations that have been performed until now have brought us to a point where our thinking ap- proximates actual programming. Nevertheless, it is still “manual programmi