-
Notifications
You must be signed in to change notification settings - Fork 0
/
IncorrectSample.bmm
64 lines (64 loc) · 1.43 KB
/
IncorrectSample.bmm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
10 REM SAMPLE PROGRAM WITH SUBROUTINES
20 REM
30 REM A IS ARRAY TO HOLD THE DATA ITEMS
40 REM I IS THE LOOP INDEX VARIABLE
50 REM X HOLDS THE VALUE WE SEEK
60 REM F IS A FLAG, 0 MEANS NOT FOUND, 1 MEANS FOUND
70 REM N IS NUMBER OF ELEMENTS IN A
80 REM
100 DIM A(19)
110 REM
120 REM
130 REM
140 REM READ DATA INTO ARRAY A
150 LET N=20
160 GOSUB 380
170 REM BELOW THIS LINE THERE IS ERROR
180 PRIN "FIND WHAT"
190 INPUT X
200 REM DO SEQUENTIAL SEARCH
210 GOSUB 470
220 REM REPORT RESULTS
230 IF F=1 THEN 260
240 PRINT X;"NOT FOUND"
250 GOTO 270
260 PRINT X;"FOUND IN SLOT";I
270 REM TRY AGAIN?
280 PRINT "TRY AGAIN"
290 INPUT A$
300 IF A$="Y" THEN 170
310 IF A$="N" THEN 340
320 PRINT "ANSWER MUST BE Y OR N!"
330 GOTO 280
340 STOP
350 REM
360 REM
370 REM
380 REM SUBROUTINE TO LOAD DATA FROM DATA STATEMENTS INTO A
390 REM INPUT N NUMBER OF ELEMENTS
400 REM OUTPUT A(), ARRAY WITH N ELEMENTS
410 REM
420 FOR I=0 TO N-1
430 REM ANOTHER COMMENT
440 NEXT I
450 RETURN
460 REM
470 REM SUBROUTINE TO DO SEQUENTIAL SEARCH FOR X IN A
480 REM INPUT N NUMBER OF ELEMENTS
490 REM INPUT A(), ARRAY WITH N ELEMENTS
500 REM INPUT X, ELEMENT VALUE TO SEARCH FOR
510 REM OUTPUT F, 0 MEANS NOT FOUND, F=1 MEANS FOUND
520 REM OUTPUT I, INDEX OF X IN A() IF F=1, N OTHERWISE
530 REM
540 LET F=0
550 FOR I=0 TO N-1
560 IF A(I)<>X THEN 590
570 LET F=1
580 GOTO 600
590 NEXT I
600 RETURN
610 REM
620 REM
630 DATA 21,85,80,14,60,76,87,49,78,81,96,25,17,22,13,91,23,62,5,57
640 REM
650 END