Easy Question I'm sure...

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Guest
Easy Question I'm sure...

Post by Guest » Sat Dec 13, 2003 2:16 pm

Hi there, I was just curious of how to do one little thing.

Let's say I wanted QBASIC to generate random numbers between 1 and 10 and based on that number, it would print out a particular word associated with that number (something I would define,) but then I would want it to do it again, but not including the previous number generated (thus not printing the same word twice if it repeats 10 times.

In case I'm not clear...
if I say that such and such variable = "joe"
and such and such variable = "mary"
and so on with eight other names...
and i want it to randomly select one of them, and then do it until all 8 names are used and none are repeated... how can I do this?

Thanks!

Robbie

Dr_Davenstein
QBasic God
Posts:166
Joined:Tue Mar 25, 2003 12:45 am
Location:U.S.A.
Contact:

Re: Easy Question I'm sure...

Post by Dr_Davenstein » Wed Dec 17, 2003 6:46 am

Here ya' go!!!
;D  :D  ;)

Code: Select all

SCREEN 13
RANDOMIZE TIMER

DIM Names$(1 TO 10)

FOR X = 1 TO 10
 READ Names$(X)
NEXT


DO
RandomName = INT(RND * 10) + 1
 IF Names$(RandomName) <> "" THEN
 &nbsp;PRINT Names$(RandomName)
 &nbsp;Names$(RandomName) = ""
 &nbsp;Counted = Counted + 1
 END IF

LOOP UNTIL Counted = 10

DATA Dr_Davenstein,has,taken,the,liberty,to,finish,your,homework,assignment
Come check out [url=http://www.freebasic.net/forum/index.php]FreeBASIC[/url]. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!

Post Reply