Computer Science Canada

Why won't it let me exit?

Author:  Hack.saw [ Sun Jun 18, 2006 12:16 pm ]
Post subject:  Why won't it let me exit?

code:

var instr : string
var guitar : int := Pic.FileNew ("guitar.bmp")
var drumset : int := Pic.FileNew ("drumset.bmp")
var keyboard : int := Pic.FileNew ("keyboard.bmp")

loop
    put "What is your favourite instrument?"
    get instr
    if instr = "guitar" then
        Pic.Draw (guitar, 100, 100, picCopy)
        delay (2000)
        cls
    elsif instr = "drums" then
        Pic.Draw (drumset, 100, 100, picCopy)

        delay (2000)
        cls
    elsif instr = "keyboard" then
        Pic.Draw (keyboard, 100, 100, picCopy)
        delay (2000)
        cls

        exit when instr = "bored"
    end if
end loop
put "Happy Father's Day!"

It won't let me exit out of this- when you type in bored its just begins again saying "What is your favourite instument?". What do I do? Embarassed

Author:  TheOneTrueGod [ Sun Jun 18, 2006 12:47 pm ]
Post subject: 

Code is linear. That exit when lies within the elsif construct "keyboard". This means that it'll only check to see if instr is "bored" when instr is "keyboard". Obviously it can't be both at once, so it'll never exit Wink . You'll want to put the exit when directly after the get line.

code:

get instr
exit when instr = "bored"

Author:  upthescale [ Sun Jun 18, 2006 4:55 pm ]
Post subject: 

the 'exit when' is inside the last if satment, try taking it out!!!!

Author:  Hack.saw [ Sun Jun 18, 2006 8:51 pm ]
Post subject: 

hehe thanks guys that was my cousin posting on my acount she just learning turing and they way she said it over the phone I couldnt figure out the problem Very Happy


: