Computer Science Canada case command help *urgent* |
Author: | RottenPunk [ 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. |
Author: | Mazer [ Thu Feb 19, 2004 6:38 pm ] | ||
Post subject: | |||
The case construct is like another way of doing if statements. A better way? Well... OK, here's how they work:
The "label 1:" part is like saying "if choice = 1", and "label :" is like the "else" at the end of your if statement. |
Author: | RottenPunk [ Thu Feb 19, 2004 7:05 pm ] |
Post subject: | |
thanks |
Author: | RottenPunk [ Thu Feb 19, 2004 7:30 pm ] | ||
Post 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"
|
Author: | Mazer [ Thu Feb 19, 2004 7:40 pm ] |
Post 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":...) |
Author: | RottenPunk [ Thu Feb 19, 2004 8:20 pm ] |
Post 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. |