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

Username:   Password: 
 RegisterRegister   
 Stopping "get" and continue program?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DarkVee




PostPosted: Fri Mar 25, 2005 7:05 pm   Post subject: Stopping "get" and continue program?

Hi, I'm making a Q&A type of program with a timer, that if the timer goes to 0, you skip to the next question. But I'm having trouble in changing into the next question when the timer reaches 0. Can anyone help me or give me some advice in fixing it?

Basically, How to I stop the get command at the bottom and go to another question? The program seems to still be stuck in get timer reaches 0.

code:

var timer_font : int
var answer : string
var timer_num : int := 10

process countdown %timer
    loop
        timer_font := Font.New ("Times New Roman:24")
        Font.Draw (intstr (timer_num), 610, 370, timer_font, 7)
        delay (1000)
        drawfillbox (600, 300, 639, 399, 0)
        timer_num -= 1
        exit when (timer_num < 0)
    end loop
    Font.Free (timer_font)
end countdown

process countdown_check %timer check
    var ch : string (1)
    loop
        if timer_num = 0 then
            put "Times Up!"
            return
        end if
    end loop
end countdown_check


put "What is answer?"
fork countdown

fork countdown_check
get answer


Thanks in advance!
Sponsor
Sponsor
Sponsor
sponsor
mike200015




PostPosted: Fri Mar 25, 2005 10:14 pm   Post subject: (No subject)

1st thing.. remove the processes.. they are EVIL!! Twisted Evil .. they can really screw up ur program
mike200015




PostPosted: Fri Mar 25, 2005 10:17 pm   Post subject: (No subject)

ok.. its becuz.. since u have processes.. and then the actual program part where sum1 enters their answer.. are not really apart of eachother.. so when the time = 0 in the time check process.. then it will put times up! but wont do nething else.. it wont stop u from entering.. so u need to try to put the whole program together in 1 procedure.. or mayb if u want do just the timer as a process.. that should help
If u need more help jus ask or pm Smile
Cervantes




PostPosted: Sat Mar 26, 2005 8:31 am   Post subject: (No subject)

This will be easier if you only need the user to input one key (ie. if you will use getch). Is this going to a multiple choice test or something? Or does the user have to enter the answer in full?
DarkVee




PostPosted: Sat Mar 26, 2005 10:33 am   Post subject: (No subject)

Quote:
so u need to try to put the whole program together in 1 procedure.. or mayb if u want do just the timer as a process.. that should help


1 Procedure? but is there a command for stopping "get "? I'm sort of stuck there.

Quote:
This will be easier if you only need the user to input one key (ie. if you will use getch). Is this going to a multiple choice test or something? Or does the user have to enter the answer in full?


Yes, apparently I need the user to answer in full, instead of multiple choice.
Cervantes




PostPosted: Sat Mar 26, 2005 11:04 am   Post subject: (No subject)

Okay, then, the only way I see of doing this is putting getch in a loop and adding whatever getch gets into a answer string. Then compare the answer string to the correct answer.

Turing:

fcn getAns (correctAns : string, TIME : int) : boolean
    var input : string (1)
    var answer := ""
    var timeCurrent := Time.Elapsed
    var secLeft := TIME
    loop
        if hasch then
            getch (input)
            if ord (input) = 10 then %enter
                if answer = correctAns then
                    result true
                else
                    result false
                end if
            else
                answer += input
            end if
        end if
        locate (2, 1)
        put answer
        if Time.Elapsed >= timeCurrent + 1000 then
            timeCurrent += 1000
            secLeft -= 1
            if secLeft < 0 then
                result false
            end if
            locate (1, 1)
            put secLeft
        end if
    end loop
end getAns

put getAns ("House of the Rising Sun", 10)


Works alright. Mind you, if you make a typo and try to backspace it out of there, you will get the answer wrong. It's easy to fix, but I'll let you do that.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: