1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-22 14:33:51 +00:00
8bitworkshop/presets/basic/tutorial.bas
2020-08-24 09:47:20 -05:00

100 lines
3.8 KiB
QBasic

OPTION DIALECT DARTMOUTH
001 REM THIS IS A PROGRAM WRITTEN IN BASIC.
002 REM YOU CAN WRITE ONE STATEMENT PER LINE.
003 REM EACH STATEMENT MUST HAVE A LINE NUMBER.
004 REM THE "REM" LINES ARE COMMENTS, WHICH ARE IGNORED
005 ' YOU CAN ALSO DO COMMENTS WITH APOSTROPHES
006 ' LET'S START WITH A "PRINT"...
100 PRINT "HELLO! LET'S PROGRAM IN BASIC."
101 PRINT ' <-- THIS PRINTS A BLANK LINE, IT LOOKS NICER
105 ' "INPUT" WAITS FOR USER INPUT FROM THE KEYBOARD
106 ' THE NUMBER ENTERED WILL GO INTO THE VARIABLE "N"
110 INPUT "FIRST, TELL ME YOUR FAVORITE NUMBER";N
111 PRINT
115 ' YOU CAN DO CALCULATIONS WITH THE + - / * OPERATORS
116 ' THE ^ IS AN EXPONENT, SO N^2 IS N-SQUARED
119 ' "LET" ASSIGNS THE RESULT TO A VARIABLE
120 LET Z = N^2
121 ' THE SEMICOLON ";" SEPARATES THINGS TO BE PRINTED
122 PRINT "THAT'S A GOOD ONE! I LIKE";Z;"MYSELF."
123 PRINT
125 ' IF A VARIABLE ENDS IN "$" IT IS A STRING
126 ' AND CONTAINS CHARACTERS INSTEAD OF A NUMBER
127 ' LET'S READ FROM THE KEYBOARD INTO THE A$ VARIABLE
130 INPUT "WOULD YOU MIND TYPING IN YOUR NAME";A$
131 PRINT
135 ' WE CAN PRINT MULTIPLE THINGS PER LINE
136 ' IN THIS BASIC DIALECT, NUMBERS ARE PRINTED
137 ' WITH SPACES BEFORE AND AFTER
140 PRINT "GOOD TO MEET YOU, ";A$;" WHO LOVES";N;"!"
141 PRINT
150 INPUT "WOULD YOU LIKE TO SEE ME CALCULATE";B$
151 PRINT
155 ' "IF" CAN TEST A CONDITION
156 ' AND JUMP TO A DIFFERENT LINE IF IT IS TRUE
160 IF B$ = "Y" THEN 180
161 IF B$ = "YES" THEN 180
170 PRINT "TOO BAD, ";A$;"! WE'RE DOING THIS."
180 PRINT
190 PRINT "WATCH ME COUNT..."
195 ' THIS "FOR" STATEMENT STARTS A LOOP WHICH SETS
196 ' VARIABLE I TO 1 AND COUNTS TO 50
200 FOR I = 1 TO 50
210 PRINT I, ' USE A COMMA FOR NEAT PRINT ZONES
220 NEXT I ' REPEAT LOOP
225 ' USING THE COMMA (OR SEMICOLON) IN THE PRINT STATEMENT
226 ' KEEPS THE CURSOR ON THE SAME LINE, SO WE PRINT
227 ' A BLANK LINE TO RETURN TO THE LEFT MARGIN
230 PRINT
240 PRINT "I CAN ALSO GRAPH TRIG FUNCTIONS!"
245 ' YOU CAN DEFINE YOUR OWN FUNCTIONS WITH "DEF"
246 ' FUNCTIONS MUST START WITH "FN"
250 DEF FNY(X) = (SIN(X*0.3)+1)*30+2
260 FOR I = 1 TO 25
270 PRINT TAB(FNY(I));"*"
280 NEXT I
300 ' YOU CAN DEFINE AN ARRAY WITH "DIM"
301 ' YOU CAN HAVE ARRAYS OF EITHER NUMBERS OR STRINGS
310 DIM T$(15),A$(15),W(15)
315 ' "READ" LOADS FROM "DATA" STATEMENTS
316 ' DATA CAN BE ANYWHERE, OURS IS AT LINE 900
320 FOR I = 1 TO 15
330 READ T$(I),A$(I),W(I)
340 NEXT I
350 ' NOW THE ARRAYS ARE FILLED WITH DATA
351 ' SO LET'S PICK A VALUE AT RANDOM
352 ' THE RND FUNCTION RETURNS A RANDOM NUMBER
353 ' FIRST WE USE "RANDOMIZE" TO INITIALIZE THE
354 ' RANDOM NUMBER GENERATOR
360 RANDOMIZE
362 ' "LET" ASSIGNS A VARIABLE FROM AN EXPRESSION
370 LET J = INT(15*RND)
380 PRINT "MY FAVORITE SONG IS '";T$(J);"'"
390 PRINT "BY ";A$(J);", DO YOU KNOW IT?"
400 PRINT "IT SPENT";W(J);"WEEKS ATOP THE CHARTS."
410 PRINT
890 ' HERE'S THE DATA WE READ EARLIER
891 ' WE CAN USE NUMBERS, QUOTED OR UNQUOTED STRINGS
900 DATA "HELLO, GOODBYE",THE BEATLES,2
901 DATA "JUDY IN DISGUISE",JOHN FRED AND HIS PLAYBOY BAND,2
902 DATA "GREEN TAMBOURINE",THE LEMON PIPERS,1
903 DATA "LOVE IS BLUE",PAUL MAURIAT,5
904 DATA "(SITTIN' ON) THE DOCK OF THE BAY",OTIS REDDING,4
905 DATA "HONEY",BOBBY GOLDSBORO,5
906 DATA "TIGHTEN UP",ARCHIE BELL & THE DRELLS,3
907 DATA "MRS. ROBINSON",SIMON & GARFUNKEL,3
908 DATA "THIS GUY'S IN LOVE WITH YOU",HERB ALPERT,4
909 DATA "GRAZING IN THE GRASS",HUGH MASEKELA,2
910 DATA "HELLO, I LOVE YOU",THE DOORS,2
911 DATA "PEOPLE GOT TO BE FREE",THE RASCALS,5
912 DATA "HARPER VALLEY PTA",JEANNIE C. RILEY,1
913 DATA "HEY JUDE",THE BEATLES,9
914 DATA "LOVE CHILD",DIANA ROSS & THE SUPREMES,2
915 DATA "I HEARD IT THROUGH THE GRAPEVINE",MARVIN GAYE,3
979 ' WE'RE DONE, SAY GOODBYE TO THE USER
980 PRINT "I APOLOGIZE, BUT I AM FATIGUED FROM ALL OF THIS"
981 PRINT "CALCULATING. I SHALL TAKE MY LEAVE OF YOU NOW."
990 PRINT "NICE MEETING YOU, ";A$;"."
998 ' PROGRAMS MUST END WITH "END" IN THIS DIALECT
999 END