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

Username:   Password: 
 RegisterRegister   
 case sector is out of range
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HaVoC




PostPosted: Fri Dec 05, 2003 2:08 pm   Post subject: case sector is out of range

code:

case boundary of
    label 100: put "I am choosing a number between 1, and 100"
    label 200: put "I am choosing a number between 1, and 200"
    label 300: put "I am choosing a number between 1, and 300"
    label 400: put "I am choosing a number between 1, and 400"
    label 500: put "I am choosing a number between 1, and 500"
    label 600: put "I am choosing a nymber between 1, and 600"
    label 700: put "I am choosing a nymber between 1, and 700"
    label 800: put "I am choosing a nymber between 1, and 800"
    label 900: put "I am choosing a nymber between 1, and 900"
    label 1000: put "I am choosing a nymber between 1, and 1000"
end case


It says case sector is out of range, what does this mean, and what do I do to fix it?

Also my random number code doesn't work....

randomize
randint(number,1,1000)
What's wrong with this?
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Fri Dec 05, 2003 2:12 pm   Post subject: (No subject)

cuz u dont have case 2, or 3, or 5 or anything except 100,200,300,400,500,600,700,800,900,1000, just have it from 1 to 10 or have num:=Rand.Int(1,10)*100
Mazer




PostPosted: Fri Dec 05, 2003 2:16 pm   Post subject: (No subject)

you need another label at the end to handle every other option. meaning, if boundary is anything other than what you have there, the case needs to know what to do:
code:

case boundary of
    label 100 :
        put "I am choosing a number between 1, and 100"
    label 200 :
        put "I am choosing a number between 1, and 200"
    label 300 :
        put "I am choosing a number between 1, and 300"
    label 400 :
        put "I am choosing a number between 1, and 400"
    label 500 :
        put "I am choosing a number between 1, and 500"
    label 600 :
        put "I am choosing a nymber between 1, and 600"
    label 700 :
        put "I am choosing a nymber between 1, and 700"
    label 800 :
        put "I am choosing a nymber between 1, and 800"
    label 900 :
        put "I am choosing a nymber between 1, and 900"
    label 1000 :
        put "I am choosing a nymber between 1, and 1000"
    label :
        put "oh no! boundary is a different number!"
end case



also, don't use randomize at the beginning of your program, turing uses it automatically every time the program is run.
HaVoC




PostPosted: Fri Dec 05, 2003 2:17 pm   Post subject: (No subject)

Ok so it'd be

code:

case boundary of
case 1:    label 100: put "I am choosing a number between 1, and 100"
end case
Mazer




PostPosted: Fri Dec 05, 2003 2:24 pm   Post subject: (No subject)

eh? not quite sure what you're asking there. just add
code:

label :
        % put stuff here to handle all other cases.


after all of your other labels, and before the end case line.

for example, if you had
code:

label :
        put "unexpected case"

at the end of the case statement thingy, and you ran the program and boundary was 5 or something else that you didn't check for in the case statement the program would put "enexpected case" on the screen
HaVoC




PostPosted: Fri Dec 05, 2003 2:25 pm   Post subject: (No subject)

Ok I got my case statements to work, but I still have a problem. I chose my number as a fixed value as 777. But it didn't say I am choosing a number between 1 and 800. -.- I think i'm missing something in my case statement Sad
HaVoC




PostPosted: Fri Dec 05, 2003 2:35 pm   Post subject: (No subject)

And also how do you end the program?
it's in an if statement

code:

if number > 99
then
(end code)
end if
Andy




PostPosted: Fri Dec 05, 2003 2:49 pm   Post subject: (No subject)

if ur not in a procedure, the return command exits the program instantly
Mazer




PostPosted: Fri Dec 05, 2003 3:09 pm   Post subject: (No subject)

HaVoC wrote:
Ok I got my case statements to work, but I still have a problem. I chose my number as a fixed value as 777. But it didn't say I am choosing a number between 1 and 800. -.- I think i'm missing something in my case statement Sad

i think you're trying to use that case statement to check if the number is in a range of values, aren't you? for this (and everything, really) it's better to use if statements. that way:

code:

if boundary < 100 then
    put "I am choosing a number between 1, and 100"
elsif boundary < 200 then
    put "I am choosing a number between 1, and 200"
elsif boundary < 300 then
    put "I am choosing a number between 1, and 300"
elsif boundary < 400 then
    put "I am choosing a number between 1, and 400"
elsif boundary < 500 then
    put "I am choosing a number between 1, and 500"
elsif boundary < 600 then
    put "I am choosing a number between 1, and 600"
elsif boundary < 700 then
    put "I am choosing a number between 1, and 700"
elsif boundary < 800 then
    put "I am choosing a number between 1, and 800"
elsif boundary < 900 then
    put "I am choosing a number between 1, and 900"
elsif boundary < 1000 then
    put "I am choosing a number between 1, and 1000"
end if


that should work out much better.
HaVoC




PostPosted: Fri Dec 05, 2003 3:18 pm   Post subject: (No subject)

I'm trying to mae it so that the random number goes into the boundary.
Say the random number was 99
it's day label 100: "i chose a numebr between 1 and 100"
Mazer




PostPosted: Fri Dec 05, 2003 3:48 pm   Post subject: (No subject)

yes, just use the if statements that i had in the last post.
Dan




PostPosted: Fri Dec 05, 2003 5:06 pm   Post subject: (No subject)

Mazer wrote:
....for this (and everything, really) it's better to use if statements.


well it dose wrok well for user menuns and anything where you the exacte posable values of the thing being tested.

but it is true that it is not need, i bet if you where able to look at the socre code for it, it whould just be some if stamnets. (that or they just uses c++ switch direlty Razz )
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
HaVoC




PostPosted: Fri Dec 05, 2003 10:48 pm   Post subject: (No subject)

Ok and 1 last thing. My randint code ain't working. I think i'm missing somehting

code:

randomize
randint(number,1,1000)
HaVoC




PostPosted: Fri Dec 05, 2003 10:52 pm   Post subject: (No subject)

dodge_tomahawk wrote:
if ur not in a procedure, the return command exits the program instantly

I have code after it though

So I have this
code:

if guess = randomnumber
then
put "Good job, you won the game in ",guessno"(es)"
end if


I have code after that if incase he doesn't get it right, it asks for guess2. How can I make the program end if he get's it right?
Dan




PostPosted: Sun Dec 07, 2003 1:29 am   Post subject: (No subject)

well i am not shure where your ifs are but i am guesing they are in a loop of some kind, in that case you can probly added an exit stament to quite the loop.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
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  [ 15 Posts ]
Jump to:   


Style:  
Search: