[Help, please!] random non-repeating questions
Author |
Message |
rainpour
|
Posted: Fri Jun 08, 2012 9:57 pm Post subject: [Help, please!] random non-repeating questions |
|
|
What is it you are trying to achieve?
I'm making a program in which the user learns about a topic and then takes a quiz to see if they can spell the names relevant to the topic correctly.
There are 10 questions.
They must be random and non-repeating.
Help is very, very much appreciated. I've become extremely frustrated over this, and none in my class have been able to help.
What is the problem you are having?
I am not able to make the questions non-repeating, even with an array, and after 10 questions, the program stays in userInput instead of going to the display. I've never even seen my display screen once.
Describe what you have tried to solve this problem
I've been on this forum, searching for anything relevant. There were some posts, but I wasn't able to apply what was there. I've used arrays, multiple different if statements etc.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is what is in procedure userInput so far. If it's not enough to base an answer on, I don't mind putting a download link of the entire program so far, along with the photos in it.
Turing: |
<procedure userInput
title
locate (20, 30)
put "Score = ", correctAnswers, "/", answeredQs
var question := Rand.Int (1, 10)
var haha : array 1 .. 10 of string
var answer : string
for x : 1 .. 10
haha (x ) := "empty"
if question = 1 then
if haha (1) = "filled" then
userInput
end if
if haha (1) = "empty" then
picID := Pic.FileNew ("trumpet.jpg")
Pic.Draw (picID, 220, 305, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (1) := "filled"
answeredQs := answeredQs + 1
if answer = "Trumpet" or answer = "trumpet" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 2 then
if haha (2) = "filled" then
userInput
end if
if haha (2) = "empty" then
picID := Pic.FileNew ("tuba.jpg")
Pic.Draw (picID, 235, 175, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (2) := "filled"
answeredQs := answeredQs + 1
if answer = "Tuba" or answer = "tuba" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 3 then
if haha (3) = "filled" then
userInput
end if
if haha (3) = "empty" then
picID := Pic.FileNew ("trombone.jpg")
Pic.Draw (picID, 220, 315, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (3) := "filled"
answeredQs := answeredQs + 1
if answer = "Trombone" or answer = "trombone" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 4 then
if haha (4) = "filled" then
userInput
end if
if haha (4) = "empty" then
picID := Pic.FileNew ("violin.jpg")
Pic.Draw (picID, 220, 175, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (4) := "filled"
answeredQs := answeredQs + 1
if answer = "Violin" or answer = "violin" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 5 then
if haha (5) = "filled" then
userInput
end if
if haha (5) = "empty" then
picID := Pic.FileNew ("guitar.jpg")
Pic.Draw (picID, 280, 180, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (5) := "filled"
answeredQs := answeredQs + 1
if answer = "Guitar" or answer = "guitar" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 6 then
if haha (6) = "filled" then
userInput
end if
if haha (6) = "empty" then
picID := Pic.FileNew ("harp.jpg")
Pic.Draw (picID, 230, 180, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (6) := "filled"
answeredQs := answeredQs + 1
if answer = "Harp" or answer = "harp" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 7 then
if haha (7) = "filled" then
userInput
end if
if haha (7) = "empty" then
picID := Pic.FileNew ("piano.jpg")
Pic.Draw (picID, 250, 180, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (7) := "filled"
answeredQs := answeredQs + 1
if answer = "Piano" or answer = "piano" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 8 then
if haha (8) = "filled" then
userInput
end if
if haha (8) = "empty" then
picID := Pic.FileNew ("gong.jpg")
Pic.Draw (picID, 220, 210, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (8) := "filled"
answeredQs := answeredQs + 1
if answer = "Gong" or answer = "gong" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 9 then
if haha (9) = "filled" then
userInput
end if
if haha (9) = "empty" then
picID := Pic.FileNew ("flute.jpg")
Pic.Draw (picID, 220, 215, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (9) := "filled"
answeredQs := answeredQs + 1
if answer = "Flute" or answer = "flute" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
elsif question = 10 then
if haha (10) = "filled" then
userInput
end if
if haha (10) = "empty" then
picID := Pic.FileNew ("clarinet.jpg")
Pic.Draw (picID, 220, 225, picMerge)
locate (15, 1)
put "What instrument do you see above? " ..
get answer
haha (10) := "filled"
answeredQs := answeredQs + 1
if answer = "Clarinet" or answer = "clarinet" then
correctAnswers := correctAnswers + 1
userInput
else
userInput
end if
end if
else
if haha (x ) = "filled" then
display
end if
end if
end for
end userInput>
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Fri Jun 08, 2012 11:18 pm Post subject: Re: [Help, please!] random non-repeating questions |
|
|
You seem to be calling userInput within userInput. This will start the procedure again, hence you will never get anywhere.
I'm not sure what you think this should be doing, but this is probably not the way to do it. |
|
|
|
|
![](images/spacer.gif) |
rainpour
|
Posted: Fri Jun 08, 2012 11:33 pm Post subject: RE:[Help, please!] random non-repeating questions |
|
|
Oh! That's probably it.
Are you saying that I should try making two separate procedures?
I'm unsure of how I'll be able to do that properly either though, but thank you for your input.
I'll keep noodling with it. |
|
|
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Sat Jun 09, 2012 2:24 am Post subject: Re: [Help, please!] random non-repeating questions |
|
|
What exactly do you expect the userInput procedure to do when it gets to a userInput call?
Turing: | if haha (1) = "filled" then
userInput <-- What do you expect this to do?
end if |
|
|
|
|
|
![](images/spacer.gif) |
rainpour
|
Posted: Sat Jun 09, 2012 7:36 am Post subject: RE:[Help, please!] random non-repeating questions |
|
|
I thought it would be enough for it to keep running the test until all of the array was filled...? Basically for it to go to another random question, but not one that it had been to before.
I have a version without an array's else written like:
Turing: |
else
if answeredQs = 10 then
display
end if
end if
|
but even with the variable answeredQs working properly, counting to 10, it never went to display. (And it was a global variable.) |
|
|
|
|
![](images/spacer.gif) |
Amarylis
|
Posted: Sat Jun 09, 2012 10:32 am Post subject: RE:[Help, please!] random non-repeating questions |
|
|
The problem with the "filled" array, is that you clear it every time you run userInput |
|
|
|
|
![](images/spacer.gif) |
|
|