Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make Questions at Random

Status
Not open for further replies.

QBGL

Programmer
Feb 3, 2003
2
US
Im creating a Quiz Program. Can someone suggest a way to generate the questions at random, and them store them somewhere so there not asked againg during the program. Thanks for your help.
 
Hello QBGL,
what sort of quiz that will be?
You see, there no way to BASIC "speak" smth of it's own.
I can suggest:
YOU create list of questions (in a file, a question per line)
read it into string array (using LINE INPUT #1)
then generate random number (say N) and show Nth element of array.
You can store N you got (and check against it) so not to ask same question twice.

I hope this can help.


 
i would use the RANDOMIZE TIMER command. then use something like this.


DO
RANDOMIZE TIMER

'this generates a different number each time

number=int(RND*100)

if number=1 then

call question1

elseif number=2 then

call question2

endif

loop
that's how i'd do it. and if you don't want the same question to repeat...

donequestion1="false"
DO
RANDOMIZE TIMER

'this generates a different number each time

number=int(RND*100)

if donequestion1="false"
if number=1 then

donequestion1="true"

call question1
endif

if donequestion2="false" then

if number=2 then

donequestion2=true

call question2

endif

you'd want to use select case though. much easier.
 
you should create and array as big as the amout of questions you will use like if you had 10 questions you would do

dim questions%(1 to 10)

the you should


do
RANDOMIZE TIMER
questionnumber=int(RND*10)+1
if question%(questionnumber)=1 then
call question questionnumber
question%(question)=0
end if
loop


 
Here is a way to do it:

DIM question$(20)

FOR I = LBOUND(question$) TO UBOUND(question$)
READ question$(I)
NEXT I

RANDOMIZE TIMER
number = INT(RND * UBOUND(question$)) + LBOUND(question$)
PRINT question$(number)
INPUT answer$

DATA What is your favorite food?, What is your age?
DATA What is your favorite color?, What is your heighth?
DATA When were you born?, What color is your hair?
DATA Do you like turnips?, What grade are you in?
DATA What is you occupation?, Do you like to fish?
ect...
 
I meant to make this completely compatible and canned prgram, but I made a mistake. Here is what I meant to put.

DIM question$(20)

ON ERROR GOTO skip:

FOR I = LBOUND(question$) TO UBOUND(question$)
READ question$(I)
NEXT I

skip:

RANDOMIZE TIMER
number = INT(RND * I) + LBOUND(question$)
PRINT question$(number)
INPUT answer$

DATA What is your favorite food?, What is your age?
DATA What is your favorite color?, What is your heighth?
DATA When were you born?, What color is your hair?
DATA Do you like turnips?, What grade are you in?
DATA What is you occupation?, Do you like to fish?
ect...
 
The Question Generator is the only thing i need to complete my program. Thx for all the ideas!
 
I noticed that you wanted to store the question, so that they would not get it again. This will do that:

DIM question$(20), catch(20), answer$(20)

ON ERROR GOTO skip:

FOR I = LBOUND(question$) TO UBOUND(question$)
READ question$(I)
NEXT I

skip:

RANDOMIZE TIMER
number = INT(RND * I) + LBOUND(question$)0
IF catch(number) = 1 THEN GOTO skip:
catch(number) = 1
PRINT question$(number)
INPUT answer$(number)

DATA What is your favorite food?, What is your age?
DATA What is your favorite color?, What is your heighth?
DATA When were you born?, What color is your hair?
DATA Do you like turnips?, What grade are you in?
DATA What is you occupation?, Do you like to fish?
ect...
 
you could also have it so it would type out the question, word for word.


common shared question as string


question="What is the capital of Texas?"
WRITEQUESTION
'writequestion is the sub.

SUB writequestion
keypress = INKEY$
questionypos = questionypos + 1
questionxpos = 33
question2 = LEN(story)
question5% = 0
question3 = 0

DO
holding$ = keypress
IF questionypos = 22 THEN
questionypos = 4
questionxpos = 33
DO: LOOP UNTIL keypress <> &quot;&quot;
clearquestionbox
END IF


question3 = question3 + 1
question5% = question5% + 1
question4 = MID$(question, question5%, 1)
questionxpos = questionxpos + 1
IF question3 > 37 AND question3 < 45 AND question4 = &quot; &quot; THEN
questionypos = questionypos + 1
questionxpos = 33
question3 = 0
END IF


IF INKEY$ <> &quot;&quot; THEN

ELSE
FOR i& = 1 TO 55000
NEXT i&
END IF
LOCATE questionypos, questionxpos
PRINT question4


LOOP UNTIL question5% = question2



here's a small look at what each string/integer is.

question: this holds the question.
question2: this holds the length of the question.
question3: this holds the information on which letter the sub is working on.
question4: this will hold the actual letter. in the end of the sub, this will be printed, then the next letter after this, and so on.
question5: same as question3, except that this will permanently show the info: question3 will revert back to 0 once it gets too big. this will make certain that the information will never go over the screen.
i%: this will delay the computer for about 1/10th of a second. Maybe less if your computer is slower.
questionypos: this will tell you which column to put the letter. it will revert back to zero when it reaches the bottom of the text.
questionxpos: this will tell you which row to put the letter. it will revert back to 33 when it reaches the end of the screen.



I don't have the time to give a complete explanation, and i'm sure some of the more experienced guys will scour over my coding to find bugs and humiliate me. ;) hint: *sarcasm*

This is in now way for you to just copy it and paste it. I would prefer for you to take a look at it. break it down and find out how it works. i never had the time to comment it, so best of luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top