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

Username:   Password: 
 RegisterRegister   
 Help with my chain program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
LiquidDragon




PostPosted: Sat May 01, 2004 2:11 pm   Post subject: Help with my chain program

ok our teacher assigned us this new assignment. Basically we have to try and guess the middle word of this phrase.

I can't get the program to stop and ask the user to guess what the word is and then continue again.
code:

%By: Jonathan Emes
%If anyone in my class used this be prepared to recieve 0                                                                                                      Jon's

proc timer

    var start, finish : int

    wallclock (start)

    loop
        wallclock (finish)
        exit when finish - start >= 5
        put finish - start + 1
        delay (1000)
    end loop

    drawfillbox (1, 100, 10, 200, 0)

end timer

proc popletter (var word2, word1, word3, word2_out : string)

    var letter : int
    var pos : array 1 .. 7 of string
    var guess : string


    for pos_set : 1 .. length (word2)
        pos (pos_set) := "* "
    end for

    for i : 1 .. length (word2)

        locatexy (40, 200)
        put word1 ..

        if length (word2) = 3 then
            put pos (1) ..
            put pos (2) ..
            put pos (3) ..
        elsif length (word2) = 4 then
            put pos (1) ..
            put pos (2) ..
            put pos (3) ..
            put pos (4) ..
        elsif length (word2) = 5 then
            put pos (1) ..
            put pos (2) ..
            put pos (3) ..
            put pos (4) ..
            put pos (5) ..
        elsif length (word2) = 6 then
            put pos (1) ..
            put pos (2) ..
            put pos (3) ..
            put pos (4) ..
            put pos (5) ..
            put pos (6) ..
        elsif length (word2) = 7 then
            put pos (1) ..
            put pos (2) ..
            put pos (3) ..
            put pos (4) ..
            put pos (5) ..
            put pos (6) ..
            put pos (7) ..
        end if

        put word3

        timer

        loop

            randint (letter, 1, length (word2))

            if letter = 1 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            elsif letter = 2 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            elsif letter = 3 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            elsif letter = 4 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            elsif letter = 5 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            elsif letter = 6 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            elsif letter = 7 and pos (letter) = "* " then
                pos (letter) := word2 (letter) + " "
                exit
            end if

        end loop

    end for

    locatexy (40, 200)
    put word1 ..
    put word2_out ..
    delay (4000)

end popletter


proc chain

    var word1, word2, word3, word2_out : string
    var rand1, rand2, rand3 : int
    var rand4, rand5 : int

    randint (rand1, 1, 2)
    randint (rand2, 3, 4)
    randint (rand3, 5, 6)
    randint (rand4, 7, 8)
    randint (rand5, 9, 10)

    for round_number : 1 .. 5

        if round_number = 1 then
            if rand1 = 1 then
                word1 := "park  "
                word2 := "bench"
                word2_out := "b e n c h "
                word3 := " mark"
            elsif rand1 = 2 then
                word1 := "haunted  "
                word2 := "house"
                word2_out := "h o u s e "
                word3 := " party"
            end if
        elsif round_number = 2 then
            if rand2 = 3 then
                word1 := "nose  "
                word2 := "job"
                word2_out := "j o b "
                word3 := " market"
            elsif rand2 = 4 then
                word1 := "car  "
                word2 := "lock"
                word2_out := "l o c k "
                word3 := " smith"
            end if
        elsif round_number = 3 then
            if rand3 = 5 then
                word1 := "old  "
                word2 := "chap"
                word2_out := "c h a p "
                word3 := " stick"
            elsif rand3 = 6 then
                word1 := "surround  "
                word2 := "sound"
                word2_out := "s o u n d "
                word3 := " board"
            end if
        elsif round_number = 4 then
            if rand4 = 7 then
                word1 := "chair  "
                word2 := "leg"
                word2_out := "l e g "
                word3 := " bone"
            elsif rand4 = 8 then
                word1 := "ice  "
                word2 := "cream"
                word2_out := "c r e a m "
                word3 := " of tartar"
            end if
        elsif round_number = 5 then
            if rand5 = 9 then
                word1 := "angel  "
                word2 := "breathe"
                word2_out := "b r e a t h e "
                word3 := " easy"
            elsif rand5 = 10 then
                word1 := "school  "
                word2 := "bus"
                word2_out := "b u s "
                word3 := " stop"
            end if
        end if

        %puts the letter in the word
        popletter (word2, word1, word3, word2_out)

    end for

end chain

chain


I really need someone to help me with this ASAP
I can get perfect then 8)

Sorry for the commenting on the top but i don't want my classmates stealing this Wink
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Sat May 01, 2004 2:18 pm   Post subject: (No subject)

Why don't u make it so that the program asks for user input everytime you reveal a letter. Like it goes from 5...1, then output "would u like to guess", if yes, then let user guess, if now, then display letter. If user guesses wrong, then display letter. Like that.
LiquidDragon




PostPosted: Sat May 01, 2004 2:27 pm   Post subject: (No subject)

HHMM... yes that may just work. I don't know why i didnt think of that before

Although it would be much better if the user hit a key and the program stops. So that is a temporary solution but if someone could still show me how to do what i want i would appreciate it.
Paul




PostPosted: Sat May 01, 2004 3:21 pm   Post subject: (No subject)

Well, the thing is, getch just stops the whole thing. Input.KeyDown won't work well with all those delays you have.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: