SOLVING SIMPLE PROBLEMS WITH BASIC
END, PRINT, LET, Constants, Variables,and Arithmetic Operations
WRITING SIMPLE BASIC PROGRAMS
Learning to solve simple problems in BASIC is somewhat like learningto write and communicate in a foreign language, with one exception—BASIC is much easier to learn. By comparison, in the average pocket dictionary there are approximately 50,000 words, but there are less than 50 keywords in BASIC. You could probably learn all these keywords in one day; however, it takes longer than one day to become a proficient programmer in the BASIC language. As with any language, knowing only the grammar or mechanics of the language is not sufficient. You also must know how to use the language to instruct the computer to solve problems.
As discussed in Chapter 1, the first step in writing a program is problemdefinition and understanding. Whether it is an elaborate application or just a simple "one time" program you wish to write, you first must understand the problem, then decide how you are going to solve it. Once this is done, you start writing the program. Challenging as it is, this can be fun; although at times it can be very frustrating. As you progress through the course, make note of how each keyword is used to instruct the computer to produce the desired result;
In this chapter, we will discuss three statements that can be used in writingsimple BASIC programs and give examples of programs. The three keywords used to construct these statements are END, PRINT, and LET.
Every program requires anEND statement, so we’ll start with it and its functions. The END statement has two functions—to indicate to the compiler (interpreter) that there are no more BASIC statements for it to translate and to terminate execution of the program. Execution of an END statement causes the computer to print a message which indicates program execution is terminated and that the computer is ready for further processing.
The format of the END statement is:
Remember, the last statement in any BASIC program must be the singlekeyword END. This means that the statement number must be the largest statement number in the program. There is no additional information required or allowed in the END statement.
The next area of consideration is printing and the uses of thePRINT state-ment. BASIC is different from other high level programming languages in that it has a predefine format for printed output. This format, referred to as standard spacing, divides the print line into a specified number of print zones or fields of a predefine length. The number and length of print zones may vary with different computers. For the purpose of this text, we will use 16 spaces per print field. Additionally, packed spacing maybe achieved through the use of punctuation in the PRINT statement.