100 INPUT N

110 IF N=INT(N) THEN 140

120 PRINT "MUST BE INTEGER."

130 GOTO 100

140 RETURN

This program asks for two numbers (which must be integers), and then prints their sum. The subroutine in this program is lines 100 to 140. The subroutine asks for a number, and if it is not an integer, asks for a new number. It will continue to ask until an integer value is typed in.

The main program prints "WHAT IS THE NUMBER," and then calls the subroutine so get the value

of the number into N. When the subroutine returns (to line 40), the value input is saved in the variable T. This is done so that when the subroutine is called a second time, the value of the first number will not be lost.

"SECOND NUMBER" is then printed, and the second value is entered when the subroutine is again called.

When the subroutine returns the second time, "THE SUM IS" is printed, followed by the sum.

T contains the value of the first number that was entered and N contains the value of the second number.

STOPPING A PROGRAM

The next statement in the program is a "STOP" statement. This causes the program to stop execution at line 90. If the "STOP" statement was excluded from the program, we would "fall into" the subroutine at line 100. This is undesirable because we would be asked to input another number. If we did, the subroutine would try to return; and since there was no "GOSUB" which called the subroutine, an RG error would occur. Each "GOSUB" executed in a program should

have a matching "RETURN" executed later. The opposite also applies: a "RETURN" should be encountered only if it is part of a subroutine which has been called by a "GOSUB."

Either "STOP" or "END" can be used to separate a program from its subroutines. "STOP" will print a message saying at what line the "STOP" was encountered.

211 ENTERING DATA

Suppose you had to enter numbers to your program that did not change each time the program was run, but you would like it to be easy to change them if necessary. BASIC contains special state- ments, "READ" and "DATA," for this purpose.

Consider the following program:

10 PRINT "GUESS A NUMBER";

20 INPUT G

30 READ D

40 IF D = -999999 THEN 90

50 IF D<>G THEN 30

60 PRINT "YOU ARE CORRECT"

70 END

90 PRINT "BAD GUESS, TRY AGAIN."

95RESTORE

100GOTO 10

110DATA 1,393,-39,28,391,-8,0,3.14,90

120DATA 89,5,10,15,-34,-999999

When the "READ" statement is encountered, the effect is the same as an INPUT statement. But, instead of getting a number from the keyboard, a number is read from the "DATA" statements.

The first time a number is needed for a READ, the first number in the first DATA statement is read. The second time one is needed, the second number in the first DATA statement is read. When the all numbers of the first DATA statement have been read in this manner, the second DATA statement will be used. DATA is always read sequentially in this manner, and there may be any number of DATA statements in your program.

The purpose of this program is to play a little game in which you try to guess one of the numbers contained in the DATA statements. For each guess that is typed in, we read through all of the numbers in the DATA statements until we find one that matches the guess.

Page 228
Image 228
Apple II manual Input N, Print Must be Integer, Stopping a Program, Entering Data, Print Guess a Number Input G Read D

II specifications

The Apple II, launched in April 1977, was one of the first highly successful mass-produced microcomputer products. It marked a significant leap in personal computing, setting standards for future developments in the industry. Created by Steve Wozniak and Steve Jobs, the Apple II differentiated itself with its user-friendly design, appealing aesthetics, and robust capabilities.

One of the standout features of the Apple II was its open architecture, which allowed users to expand and enhance the computer's functionality. This design enabled hundreds of third-party hardware and software developers to contribute to its ecosystem, resulting in an array of peripherals, including printers, modems, and storage devices. The Apple II utilized a MOS Technology 6502 microprocessor running at a clock speed of 1 MHz. Initially equipped with 4 KB of RAM, the machine could be expanded to 48 KB, accommodating more complex applications and programs.

The Apple II was also notable for its colorful graphics. It was one of the first computers to support color display, offering a 6-color palette with a resolution of 280x192 pixels in 16 colors when using its Color Graphics Card. This feature significantly enhanced the visual appeal of games and educational software developed for the platform, making computing more accessible and entertaining for various audiences.

Apple's commitment to user experience was evident in the design of the machine. It featured an integrated keyboard and a plastic case, which was both durable and visually appealing. The self-contained design included drive bays for floppy disk drives, allowing for quicker data access than traditional tape drives. It also supported audio output, enabling sound effects and music, a novelty at the time.

The introduction of the Apple DOS operating system further underscored the machine's capabilities. DOS streamlined file management and made it easier for users to navigate and manage their data. The combination of hardware and software positioned the Apple II as an educational tool and a gaming platform, fostering a vibrant software ecosystem.

The Apple II family continued to evolve, with variations like the Apple II+, IIe, and IIgs being introduced over the years. These iterations brought enhancements in memory, processing power, and graphics capabilities. The legacy of the Apple II endures, not only as a foundational product in personal computing but also as a symbol of innovation that paved the way for future advancements in technology. Its impact is still felt today, as it inspired countless developers and shaped the trajectory of the computer industry.