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

Username:   Password: 
 RegisterRegister   
 case command help *urgent*
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RottenPunk




PostPosted: Thu Feb 19, 2004 5:52 pm   Post subject: case command help *urgent*

hey. i have an assignment due tomorrow and i need to add something into my program using the case command but i can't remember exactly how to execute it. could someone give me a short example of how it is used. i know that I have to list the options by 'puting' "(1)this,this,this"
"(2)that,that,that"
and then later on saying label 1: put"etc,etc."
lable 2: put "etc,etc"
but i cant remeber the exact usage. can anyone help me.
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Thu Feb 19, 2004 6:38 pm   Post subject: (No subject)

The case construct is like another way of doing if statements. A better way? Well...

OK, here's how they work:
code:

var choice : int

put "Mazer (in real life) is of which ethnic origin?"
put "1. Japanese"
put "2. Irish"
put "3. Canadian"
put "4. Greek"
put "5. Lebanese"
put "6. Chinese"
get choice

case choice of
    label 1 :
        put "That might be cool. I'd be able to read Naruto every week!"
    label 3 :
        put "Well, that is my nationality, but not my ethnic origin. Sorry"
    label 4 :
        put "OPA! Good for you, kid, you got it. So, there you go."
    label :
        put "You are far too wrong"
end case

The "label 1:" part is like saying "if choice = 1", and "label :" is like the "else" at the end of your if statement.
RottenPunk




PostPosted: Thu Feb 19, 2004 7:05 pm   Post subject: (No subject)

thanks
RottenPunk




PostPosted: Thu Feb 19, 2004 7:30 pm   Post subject: (No subject)

i tried what you said and most of it appears to be right but i was getting an error around the "label 1,2,3,4" that said "case alternative label is the wrong type"
code:
put "Which of the following languages can you speak fluently (type the number that corresponds"
put "with your answer:"
put "(1) French and Irish"
put "(2) French and Spanish"
put "(3) Spanish and Irish"
put "(4) Any other language(s)"
get fluency
case fluency of
label (1):put "Good."
put "Final Question..."
label 2:put "Sorry. Those are not the languages that we are currently looking for in an agent."
put "You do not qualify for CSIS...LOSER!"
label 3:put "Sorry. Those are not the languages that we are currently looking for in an agent."
put "You do not qualify for CSIS...LOSER!"
label 4:put "Sorry. Those are not the languages that we are currently looking for in an agent."
put "You do not qualify for CSIS...LOSER!"
label:put "You obviously were not listening. You definatley aren't CSIS material...LOSER!"
end case
Mazer




PostPosted: Thu Feb 19, 2004 7:40 pm   Post subject: (No subject)

Really? I ran it without problems. Well, actually, you didn't declare fluency, but after I declared it the rest of the program was just fine.
Did you have fluency as an integer in your program? Or string? Becasue if you had it as a string you would have to put quotes around each of the numbers (eg, label "1":...)
RottenPunk




PostPosted: Thu Feb 19, 2004 8:20 pm   Post subject: (No subject)

ya ur right. i could have sworn that i had fluency as an integer but i looked at the top of my page and i must have declared it as a string accidentally. i know i didnt do that earlier because the same program that i have at school works...i just forgot to send it to my computer at home. thanks for your help.
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: