
-----------------------------------
Curt12345
Tue Jan 02, 2007 5:31 pm

Quiz using Case command
-----------------------------------
I am doing a project and we need to use the case command to make a quiz. I know how the case works but I am stumped as to how to dummyproof it so the user can't enter random info. I want it so they can only enter A, B, C or D.

Can someone post an example of a quiz using the case command that is dummyproofed? Also it has to be more then one question if that means anything  :?

-----------------------------------
Prince Pwn
Tue Jan 02, 2007 6:07 pm


-----------------------------------
This is an example directly from the Turing Help Menu. 

% The "case2" program.
var name : string
put "Enter the name of an animal: " ..
get name
case name of
    label "horse", "cow" :
        put "Farm animal"
    label "tiger", "lion" :
        put "Jungle animal"
    label "cat", "dog" :
        put "Pet"
    label :
        put "Unknown animal"
end case


Now I am unfirmilliar with cases in Turing, but in that above example it seems that the last label is for an entry that is not listed in the other labels. 

If the teacher allows you to use if statements along with the label, use an if statement in your last label inside a loop to make it return to the beginning of the loop.

-----------------------------------
Hackmaster
Tue Jan 02, 2007 6:29 pm


-----------------------------------
what you want is the getch() function. make a variable (type char) and get it using getch.



var x: char

getch(x)

%case loop here.



easy. loop it and only break the loop if it's valid input. ok? easy-peasy.

-----------------------------------
Curt12345
Tue Jan 02, 2007 8:51 pm


-----------------------------------
Yeh, I know getch I just wasn't sure about the label for useless info. So my coding should be like so, correct?



loop

getch (x)

case x of:
label "neededInfo":
exit
label :
put "Enter needed info"
end case

end loop

