## The fifth program.

To enable MiniBasic to compute complicated functions we need access to arbitrary amounts of memory. For this we have the DIM statement. It creates a special type of variable known as an array.

`10 REM Calendar program.
20 DIM months$(12) = "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
30 PRINT "Day of birth?"
40 INPUT day
50 PRINT "Month?"
60 INPUT month
70 REM Make sure day and month are legal
80 IF day >= 1 AND day <= 31 AND month >= 1 AND month <= 12 THEN 110
90 PRINT "That's impossible"
100 GOTO 30
110 IF day <> INT(day) OR month <> INT(month) THEN 90
120 PRINT "Your birthday is", day, months$(month)
`

You might want to modify this program to contain another array, this time a numerical one, containing the lengths of the months. For the ambitious, you could also input the year, and check for February 29th.

Arrays can have up to five dimensions. For instance you might want to hold a chessboard in a 2d array

`DIM board(8,8)
`

It is possible to redimension arrays. For a 2d or higher array this effectively scrambles the contents, but one dimensional arrays are preserved.

For instance this program will enter an arbitrary number of values into an array

`10 REM Median program.
20 LET N = 0
30 DIM array(N+1)
40 PRINT "Enter a number, q to quit"
50 INPUT line$
60 IF line$ = "q" THEN 100
70 LET N = N + 1
80 LET array(N) = VAL(line$)
90 GOTO 30
100 PRINT N, "numbers entered"
105 IF N = 0 THEN 1000
106 IF N = 1 THEN 210
110 REM Bubble sort the numbers
120 LET flag = 0
130 LET i = 1
140 IF array(i) <= array(i+1) THEN 190
150 LET flag = 1
160 LET temp = array(i)
170 LET array(i) = array(i+1)
180 LET array(i+1) = temp
190 LET i = i + 1
195 IF i < N THEN 140
200 IF flag = 1 THEN 120
210 REM print out the middle
220 IF N MOD 2 = 0 THEN 250
230 LET mid = array( (N + 1) / 2)
240 GOTO 270
250 LET mid = array(N/2) + array(N/2+1)
260 LET mid = mid/2
270 PRINT "Median", mid
1000 REM end
`