Here - 1000 BiT

Here - 1000 BiT Here - 1000 BiT

11.07.2015 Views

THE GET COMMAND FOR NUMBERSThe GET command can be used to input numbers. If no key has been pressed/thenumber will be zero. Try this:Enter and run 10 GET N:IF N=0THEN 1015 PRINT N20 GOTO 10Press number keys. Now press a letter key. You see9SYNTAX ERRORwhen you try to GET a letter character in a numeric variable.Assignment 23:1. Write a program which has a "menu" for the user to choose from. The user makes herchoice by typing a single letter. Use GET to get the letter. Example:PRINT "WHICH COLOR? "The program changes the border color to the user's choice.2. Write a sentence making game. Each sentence has a noun subject, a verb and anobject. The first player types a noun (like "The donkey"). The second player types averb (like "sings"). The third player types another noun (like "the toothpick."). UseGET so no player can see the words of the others. You may expand the game byhaving adjectives before the nouns.134

^ INSTRUCTOR NOTES 24 PRETTY PROGRAMS, GOSUB, RETURN, END^ This lesson covers subroutines. The END command is also treated here because theprogram will usually have its subroutines at high line numbers and so must END in themiddle line numbers.Like GOTO, GOSUB causes a jump to another line number. The only difference is that inr^ GOSUB, control returns to the calling line after the subroutine is finished executing. Thisis accomplished by storing the line number following the GOSUB line on a stack. WhenO the computer encounters a RETURN statement, it pops the line number off the stack andreturns control to that line.^ Subroutines are useful not only in long programs but also in short ones where "chunking"the task into sections leads to clarity.One of the hardest habits to form in some students (and even some professionals) is to^ impose structure on the program. Structuring has gone by many names such as"structured programming" and "top down programming" and uses various techniques toDdiscipline the programmer.Call the student's attention to ways in which structuring can be done, and the advantagesr*\ in clarity of thought and ease of programming which result. In this book, writing goodREM statements and using modular construction in the program are the main techniques^offered.^QUESTIONS:O 1. What happens when the command END is executed?^ 2. How is GOSUB different from GOTO?3. What happens when RETURN is executed?o ■ ■■ -■■■■ •4. If RETURN is executed before GOSUB, what happens?n ■ ■ . ■ " '-■ " ■■■', '.5. What does "call the subroutine" mean?^ 6. How many END commands are you allowed to put into one program?^ 7. Why do you want to have subroutines in your programs?nnn135

THE GET COMMAND FOR NUMBERSThe GET command can be used to input numbers. If no key has been pressed/thenumber will be zero. Try this:Enter and run 10 GET N:IF N=0THEN 1015 PRINT N20 GOTO 10Press number keys. Now press a letter key. You see9SYNTAX ERRORwhen you try to GET a letter character in a numeric variable.Assignment 23:1. Write a program which has a "menu" for the user to choose from. The user makes herchoice by typing a single letter. Use GET to get the letter. Example:PRINT "WHICH COLOR? "The program changes the border color to the user's choice.2. Write a sentence making game. Each sentence has a noun subject, a verb and anobject. The first player types a noun (like "The donkey"). The second player types averb (like "sings"). The third player types another noun (like "the toothpick."). UseGET so no player can see the words of the others. You may expand the game byhaving adjectives before the nouns.134

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!