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

Username:   Password: 
 RegisterRegister   
 Quiz using Case command
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Curt12345




PostPosted: Tue Jan 02, 2007 5:31 pm   Post subject: 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 Confused
Sponsor
Sponsor
Sponsor
sponsor
Prince Pwn




PostPosted: Tue Jan 02, 2007 6:07 pm   Post subject: (No subject)

This is an example directly from the Turing Help Menu.
code:

% 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




PostPosted: Tue Jan 02, 2007 6:29 pm   Post subject: (No subject)

what you want is the getch() function. make a variable (type char) and get it using getch.

code:


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




PostPosted: Tue Jan 02, 2007 8:51 pm   Post subject: (No subject)

Yeh, I know getch I just wasn't sure about the label for useless info. So my coding should be like so, correct?


code:

loop

getch (x)

case x of:
label "neededInfo":
exit
label :
put "Enter needed info"
end case

end loop
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: