Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Help With Randomizing the sequence of a quiz or anything like a quiz.
Author Message
shams1204

Posted: Sun Dec 17, 2017 7:54 pm   Post subject: Help With Randomizing the sequence of a quiz or anything like a quiz.

What is it you are trying to achieve?
I am trying to randomize the question pattern in my project. For example I have ten questions and the pattern of how the computer will ask the user the questions will be different.

What is the problem you are having?

Describe what you have tried to solve this problem
I tried using the rand but i dont know how to do it with the strings .

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

 Turing:

Please specify what version of Turing you are using

TokenHerbz

Posted: Mon Dec 18, 2017 4:07 am   Post subject: RE:Help With Randomizing the sequence of a quiz or anything like a quiz.

Posted: Mon Dec 18, 2017 6:00 pm   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

Make an array, put ur question in there and have randint chose a cell in the array randomly. When the question has been answered, the cell is replaced with a filler word where if the filler word is in a cell it will redo the random int and pick another cell (assuming you want each question to only be asked once).
shams1204

Posted: Tue Dec 19, 2017 7:11 pm   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

Okay so I did this and I dont know if i am doing it correctly. Help me with this please. And how do I make the randint choose a cell for once so that it asks the question only once.
This is my code so far:

procedure randomQuestions
randint (randQuestions,1,4)

for x: 1..4
questions (x) := 1
end for

for x: 1..4
if repeatQuestions = randomQuestions (x) then
repeatQuestions := false
end if
end for
end randomQuestions

var repeatQuestions:boolean:=true
var questions: array1..4 of string
var randQuestions:int

these are my variables.

Posted: Wed Dec 20, 2017 11:20 am   Post subject: RE:Help With Randomizing the sequence of a quiz or anything like a quiz.

after you go into that cell and ask the question replace it with a value so that if that value is in the cell that your rand int chooses, it goes back to the rand int line and selects a different cell. Also, im sorry but the code you wrote dosent make any sense to me... it has 6 errors.

Posted: Wed Dec 20, 2017 11:50 am   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

With the code you gave me this is what i assummed you meant. If not, can i get more detail??
 code: var questions: array 1..10 of string var asdf:int for i:1..10 questions(i):="question: "+ intstr(i) end for procedure randthing randint(asdf,1,10) end randthing loop delay(1000) randthing if questions(asdf) not= "X" then put questions(asdf) questions(asdf):="X" end if end loop
shams1204

Posted: Thu Dec 21, 2017 9:15 am   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

Thank You for the code but its a quiz so I need the question to be displayed once only. The code works, thank you but what should I change in it so that it displays the questions only once. I'll send you my work. My work has a lot other things. Sorry if it bothers you. I also have a lot of things to fix but just look at my thing.

Thematic Personality Game Remastered.t
Description:
Filename:  Thematic Personality Game Remastered.t
Filesize:  10.83 KB

TokenHerbz

Posted: Thu Dec 21, 2017 5:21 pm   Post subject: RE:Help With Randomizing the sequence of a quiz or anything like a quiz.

please take a look at flexible arrays, you want to remove the question after its displayed to avoid duplicates.

http://compsci.ca/v3/viewtopic.php?t=7390

http://compsci.ca/holtsoft/doc/flexible.html

you should play around with it and understand how it works otherwise you'll have a big headache.

 Turing: %%%%FLEXibLE array is key to victory!!! var questions : flexible array 0 .. 2 of string %%should populate via txt file questions(0) := "A" questions(1) := "B" questions(2) := "C" %%example of how your doing it -> duplicates can happen for i: 0 .. 2     put questions(Rand.Int(0,2)) end for put "----br----" put "" %%you can use a counter to check if its been posted yet %% but i wouldn't recommend this way, its wasteful of resources %%so.... %%how to correctly do it is to %%remove array elements after its used to avoid duplicates loop        var r : int := Rand.Int(0,upper(questions))     var question : string := questions(r)     questions(r) := questions(upper(questions))     new questions, upper (questions) - 1     put question     exit when upper(questions) < 0 end loop
shams1204

Posted: Thu Dec 21, 2017 6:53 pm   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

Sorry but we are not allowed to use flexible arrays. Just arrays and randint, not Rand.Int because we still didn't learn it yet.
TokenHerbz

Posted: Fri Dec 22, 2017 12:47 am   Post subject: RE:Help With Randomizing the sequence of a quiz or anything like a quiz.

ranint is just a proc so you can still use it just modify it then, and if your not aloud to use flexible arrays just have a counter inside the loop to fine which question was posted to avoid posting it again.
TokenHerbz

Posted: Fri Dec 22, 2017 5:55 pm   Post subject: RE:Help With Randomizing the sequence of a quiz or anything like a quiz.

 Turing: var questionsToBePosted : array 0 .. 2 of string var postedQuestions: array 0 .. 2 of boolean %%should have questions populate via txt file questionsToBePosted(0) := "A" questionsToBePosted(1) := "B" questionsToBePosted(2) := "C" %%example of how your doing it -> duplicates can happen var r : int %%set var for random number cuz ur teachers a meanie for i: 0 .. 2 %%Normsl turing standards start at 1, however i count 0 as 1                 %%ex 0..9 = 1 .. 10, its more standard you'll find... (least i do)     randint(r,0,2) %% PROC CHANGE FROM FuncTION rand.int -ask ur teacher tho cuz its better     put questionsToBePosted(r) end for put "----br----" put "" %%set all questions not posted for i: lower(postedQuestions) .. upper(postedQuestions)     postedQuestions(i):= false end for var randomQnum: int loop     %%dumb way to solve this problem     for i: lower(questionsToBePosted) .. upper(questionsToBePosted)         randint(randomQnum,lower(questionsToBePosted),upper(questionsToBePosted))         if postedQuestions(i) not= true then %% practice != thx             if randomQnum = i then                 %%set we post this true and post it                 put questionsToBePosted(i)                 %%set question posted                 postedQuestions(i) := true             end if         end if     end for end loop %%tell ur teacher you need to learn the why before the how %% because this method on a large scale is very %% innoffective, and very poor code, since it can run 100x without hitting %% and escape, large scale would never fly...
shams1204

Posted: Sun Dec 24, 2017 3:18 pm   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

Um Thank You for helping me with this problem. I finally solved it but I have another Question. In my program I have buttons included and as I have random questions, I cannot say that this is question 1 and this is question 2. How do I do it. I tried this and it kind of works but it doesnt show my GUI Buttons. What should I do.

Code I tried to use for this problem:

% Program User Input
procedure userInput
for x:1..4
title
put "YOU ARE ON QUESTION ",x,"."
randomQuestions
if randQuestion = 1 then
firstQuestion

elsif randQuestion = 2 then
secondQuestion

elsif randQuestion = 3 then
thirdQuestion

elsif randQuestion = 4 then
fourthQuestion

end if
end for
end userInput

My whole project is given Below.

Thematic Personality Game Remastered.t
Description:
Filename:  Thematic Personality Game Remastered.t
Filesize:  16.99 KB

TokenHerbz

Posted: Tue Dec 26, 2017 7:03 pm   Post subject: RE:Help With Randomizing the sequence of a quiz or anything like a quiz.

i'm not sure what exactly you mean, what is it you wanted to accomplish?

browsing your code is a bit confusing so i'd like to know specifically, to better assist you, thanks.
shams1204

Posted: Tue Dec 26, 2017 7:20 pm   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

Never mind. I managed to solve the problem by my own. Thank you btw for all the help.

Thematic Personality Game Remastered.t
Description:
Filename:  Thematic Personality Game Remastered.t
Filesize:  16.99 KB

shams1204

Posted: Tue Jan 02, 2018 11:38 am   Post subject: Re: Help With Randomizing the sequence of a quiz or anything like a quiz.

I just have one more problem. My program doesn't repeat itself after it the user has answered all the questions. It doesn't randomize either. Actually it stops there. Can u check why this happens. My project is given below. I havent finished it yet. I have done only 13 questions. I need to do 7 more but please help.

Thematic Personality Game Remastered.t
Description: