09-28-2003, 11:21 PM
i am making a program to asign 16 random number 1-16 to 16 inputed names. i cant figuer out how to set up the varriables. i know you need to use DIM names(16,16) or some thing like that.
names(1) = "Billybob"
names(2) = "Bobbybill"
names(3) = "Bubba"
etc....
names(16) = "Bubba-Ray Jr"
PRINT names(3)
DIM names(1 TO 16) AS STRING
FOR i = 1 TO 16
READ names(i)
NEXT
GOSUB printNames
END
printNames:
FOR i = 1 TO 16
PRINT names(i); i
NEXT
RETURN
DATA Adam, Bertha, Charles, Danielle, Eddie, Frances, Gary, Helen, Ian, Jackie, Karl, Lucy, Marcus, Nelly, Oscar, Paula
' This randomizes a list of names, so the index becomes a
' random number assigned to the name.
DIM Names(1 to16) AS STRING
Restore NameList ' This isn't necessary unless you have multiple data lists
FOR j = 1 TO 16
READ Names(j)
NEXT
FOR j= 1 TO 16
Temp$ = Names(j)
r = INT(RND * 16 +1)
Names(j) = Names(r)
Names(r) = Temp$
NEXT
' your code
END
NameList:
DATA Alice,Bob,Cindy,Dave,and so on
' This randomizes a list of numbers
DEFINT A-Z
DIM Names(1 to16) AS STRING
DIM RndmNmbr(1 to 16)
Restore NameList ' This isn't necessary unless you have multiple data lists
FOR j = 1 TO 16
READ Names(j)
RndmNmbr(j) = j
NEXT
FOR j= 1 TO 16
Temp = RndmNmbr(j)
r = INT(RND * 16 +1)
RndmNmbr(j) = RndmNmbr(r)
RndmNmbr(r) = Temp
NEXT
' your code
END
NameList:
DATA Alice,Bob,Cindy,Dave,and so on
DIM names.string$(1 TO 16) AS STRING
DIM names.index%(1 TO 16) AS INTEGER
'put in your names by assigning to an array manually or through a file...
'.........
'
FOR i% = 1 TO 16
SWAP names.index%(INT(RND*16)+1), names.index%(i%)
NEXT i%
FOR i% = 1 TO 16
PRINT names.string$(names.index%(i%)); names.index%(i%)
NEXT i%
for i = 1 to 16
input "student name: ",names.string$(i)
next
OPEN "names" FOR INPUT AS #1
FOR i = 1 TO 16
WHILE NOT EOF(1)
INPUT #1 names.string$(i)
WEND
NEXT