Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 What's wrong with my code?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
P-Nut311




PostPosted: Wed Dec 15, 2004 8:40 pm   Post subject: What's wrong with my code?

I'm telling my program to randomize between 2 different questions, but it only randomizes the first one over and over again. How do I make it so that the program randomizes these two questions, BUT DOESN'T REPEAT THEM. Example: Question 2 can appear before question 1, but once question 2 is answered correctly, it will not appear again until the user manually starts the game over.

Heres the randomize part of the code:

code:

%Randomize First History Question
    loop
        randomize
        randint (history, 1, 2)
        if history = 1 then
            var fonthistory1 : int := Font.New ("Cooperplate Gothic Bold:14:bold")
            Font.Draw ("What did World War II have that World War I didn't have?", 95, 400, fonthistory1, yellow)
            delay (1000)
            var fontairplanesandtanks : int := Font.New ("Cooperplate Gothic Bold:14:bold")
            Font.Draw ("1. Airplanes and Tanks", 50, 350, fontairplanesandtanks, yellow)
            delay (1000)
            var font10000moresoliders : int := Font.New ("Cooperplate Gothic Bold:14:bold")
            Font.Draw ("2. 10,000 More Soldiers", 400, 350, font10000moresoliders, yellow)
            delay (1000)
            var fontatomicbombs : int := Font.New ("Cooperplate Gothic Bold:14:bold")
            Font.Draw ("3. Atomic Bombs", 50, 250, fontatomicbombs, yellow)
            delay (1000)
            var fontmustardgas : int := Font.New ("Cooperplate Gothic Bold:14:bold")
            Font.Draw ("4. Mustard Gas", 400, 250, fontmustardgas, yellow)
            delay (1000)
            var fonthistory1answer : int := Font.New ("Cooperplate Gothic Bold:14:bold")
            Font.Draw ("Answer: ", 0, 200, fonthistory1answer, yellow)
            locate (19, 12)
            put "" ..
            get historyanswer1
            case historyanswer1 of
                label 1 :
                    var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("Incorrect!", 300, 100, fontwrong, yellow)
                label 2 :
                    var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("Incorrect!", 300, 100, fontwrong, yellow)
                label 3 :
                    var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("Correct!", 300, 100, fontwrong, yellow)
                label 4 :
                    var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("Incorrect!", 300, 100, fontwrong, yellow)
                label :
                    var fontnotvalid : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("That is not a choice.", 250, 100, fontnotvalid, yellow)
                    delay (1000)
            end case
            delay (1000)
            if historyanswer1 = 3 then
                counter := counter + 1
                cls
                drawline (645, 0, 645, 755, red)
                Font.Draw ("1.              $100", 650, 10, font50, black)
                Font.Draw ("2.              $200", 650, 30, font100, cyan)
                Font.Draw ("3.              $300", 650, 50, font200, red)
                Font.Draw ("4.              $400", 650, 70, font300, red)
                Font.Draw ("5.              $500", 650, 90, font500, green)
                Font.Draw ("6.           $1,000", 649, 110, font1000, red)
                Font.Draw ("7.           $2,000", 649, 130, font2000, red)
                Font.Draw ("8.           $4,000", 649, 150, font4000, red)
                Font.Draw ("9.           $8,000", 649, 170, font8000, red)
                Font.Draw ("10.       $16,000", 648, 190, font16000, green)
                Font.Draw ("11.       $32,000", 648, 210, font32000, red)
                Font.Draw ("12.       $64,000", 648, 230, font64000, red)
                Font.Draw ("13.     $125,000", 647, 250, font16000, red)
                Font.Draw ("14.     $500,000", 647, 270, font500000, red)
                Font.Draw ("15.  $1,000,000", 646, 290, font1million, yellow)
                exit when historyanswer1 = 1 or historyanswer1 = 2 or historyanswer1 = 4
                if history = 2 then
                    var fonthistory2 : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("Who was Sir Wilfred Laurier?", 95, 400, fonthistory2, yellow)
                    delay (1000)
                    var fontcanadianprimeminister : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("1. Canadian Prime Minister", 50, 350, fontcanadianprimeminister, yellow)
                    delay (1000)
                    var fontgovernor : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("2. Governor", 400, 350, fontgovernor, yellow)
                    delay (1000)
                    var fontmayor : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("3. Mayor", 50, 250, fontmayor, yellow)
                    delay (1000)
                    var fontsenator : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("4. Senator", 400, 250, fontsenator, yellow)
                    delay (1000)
                    var fonthistoryanswer2 : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                    Font.Draw ("Answer: ", 0, 200, fonthistoryanswer2, yellow)
                    locate (19, 12)
                    put "" ..
                    get historyanswer2
                    case historyanswer2 of
                        label 1 :
                            var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                            Font.Draw ("Incorrect!", 300, 100, fontwrong, yellow)
                        label 2 :
                            var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                            Font.Draw ("Incorrect!", 300, 100, fontwrong, yellow)
                        label 3 :
                            var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                            Font.Draw ("Correct!", 300, 100, fontwrong, yellow)
                        label 4 :
                            var fontwrong : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                            Font.Draw ("Incorrect!", 300, 100, fontwrong, yellow)
                        label :
                            var fontnotvalid : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                            Font.Draw ("That is not a choice.", 250, 100, fontnotvalid, yellow)
                            delay (1000)
                    end case
                end if
            end if
        end if
    end loop
end if
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Dec 15, 2004 10:33 pm   Post subject: (No subject)

haven't you posted that before? Confused
Quote:

randint (history, 1, 2)

After you randomly picked a number (out of all possible rights and wrongs btw), you also forgot to check it against the list of wrong outputs. So

code:
if my_random_number = something_it_is_not_suppost_to_be then
try_again()
end if
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
P-Nut311




PostPosted: Wed Dec 15, 2004 11:03 pm   Post subject: (No subject)

What is "try_again()"?

Can you give me an example of code that randomizes, lets say, 5 questions of type string, but doesn't repeat the questions? I'm making a 'game show' type of game, so questions are to be randomized, but only appear in the game once.
Tony




PostPosted: Wed Dec 15, 2004 11:22 pm   Post subject: (No subject)

random numbers without repetition
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
P-Nut311




PostPosted: Thu Dec 16, 2004 4:40 pm   Post subject: (No subject)

ok...

My teacher says I need an array in order to randomize 'strings'. How do I set up an array and randomize the strings at the same time. Would my code go like this... ?

loop
randomize
var history : array 1..5 of string
[code continues]

History is of type 'string', so from what my teacher told me, strings cannot be randomized with the 'randint' command. But he said to put some randomize command before the array command, so that the questions will be randomized.

How do I do this? Can anyone give me an example?
Tony




PostPosted: Thu Dec 16, 2004 5:12 pm   Post subject: (No subject)

tony wrote:
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
P-Nut311




PostPosted: Thu Dec 16, 2004 5:21 pm   Post subject: (No subject)

"I wrote up this little piece of code for a question on this exact topic."

Don't tell me... I... nah.... Razz
P-Nut311




PostPosted: Thu Dec 16, 2004 5:53 pm   Post subject: (No subject)

so, would my code go something like this...?

var hold : string
var question : array 1..5 of string
for i : 1..5
question (i) := i
end for

for i : 1..5
hold := randint (question, 1, 5)
put question (hold)
question (hold) := question (i)
end for

-----
What does 'i' do? How do I make it so that whatever question the program chooses, it will put it in a special font using the 'Font.Draw' command?

Would I need to create a counter? I want the game to randomize the first 5 questions, which are beginner questions. After the user passes the 5th question, then the program will randomize questions 6 - 10, which are moderate questions. How would I do that? With a counter?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Dec 16, 2004 6:06 pm   Post subject: (No subject)

yes
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
P-Nut311




PostPosted: Thu Dec 16, 2004 6:32 pm   Post subject: (No subject)

Can u explain what each line of code does? I'm confused. Confused
P-Nut311




PostPosted: Thu Dec 16, 2004 11:27 pm   Post subject: (No subject)

Ok, I think I'm getting this now. I got the code to work, but it outputs intergers only. What must I do to the code to make the program output a random question (word problem)? The array also never stops, is it because it has a loop?

Ok... let's say I want the variable 'historyquestion1' to display "Who made Turing?" on the screen. Question 2 will ask "When was Turing made?". Question 3 will ask "dgsa?" and so on.... how do I make the program display these questions?

code:

    loop
        var history : int
        var randomquestion : int
        var historyquestion : array 1 .. 5 of int
        var historyquestion1 := "J"
        var historyquestion2 := "H"
        var historyquestion3 := "d"
        var historyquestion4 := "w"
        var historyquestion5 := "s"
        for i : 1 .. 5
            historyquestion (i) := i
        end for

        for decreasing i : 5 .. 1
            randomquestion := Rand.Int (1, i)
            put historyquestion(randomquestion)
            historyquestion (randomquestion) := historyquestion(i)
        end for
            end loop
    end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: