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

Username:   Password: 
 RegisterRegister   
 Chances of stopping
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
compudave




PostPosted: Wed Nov 12, 2003 8:04 pm   Post subject: Chances of stopping

Can anyone help me out by explaining how to incorporate a chance of stopping a count loop. For exanple how to get a counted loop to have a 50% of stopping before it reaches 10.
Sponsor
Sponsor
Sponsor
sponsor
Chimaera




PostPosted: Wed Nov 12, 2003 8:10 pm   Post subject: (No subject)

well all you really have to do is make an exit when statement with a randint

code:


for i: 1..10
var num : int
randint (num,1,2)
exit when num = 2
count := count+1
if count = 10
then put "Hurray, you hit 10"
end if
end for
if num = 2
then put "Aw shucks, you beat me to the punch. ;_;"
end if


Well that's basically the code you need, but why would you WANT to stop your forloop before it hits 10?
Karam




PostPosted: Wed Nov 12, 2003 8:59 pm   Post subject: (No subject)

hehe dave got it before u lol Laughing


code:
var num : real
randomize
for count : 1 .. 10
    rand (num)
    exit when num <= .50
    put count
end for
nis




PostPosted: Sun Nov 16, 2003 3:31 am   Post subject: (No subject)

That is not a 50% chance of exiting before hitting 10

Your code has a 50% chance everytime you go through the loop

I am not sure exactly what the numbers are but i think if you're going through the loop 10 times then the code should be:
code:

var num : real
var count : int := 0
randomize
loop
    count += 1
    rand (num)
    exit when num <= .05 or count = 10
end loop
if count = 10 then
    put "You got to 10"
else
    put "You only got to ", count
end if
Andy




PostPosted: Mon Nov 17, 2003 6:41 pm   Post subject: (No subject)

ummm
code:

for i: 1..10
exit when Rand.Int(0,1)
end for
Mazer




PostPosted: Mon Nov 17, 2003 6:51 pm   Post subject: (No subject)

dodge, dodge, dodge... this isn't c++

code:

for i : 1 .. 10
    exit when Rand.Int (0, 1) = 1
end for


although i'm still not sure that would be correct for having a 50% chance of exiting before reaching ten. with that code there's a 50% chance of exiting at every repetition. so... yeah...
Andy




PostPosted: Mon Nov 17, 2003 6:53 pm   Post subject: (No subject)

sutpid turing... lol
Andy




PostPosted: Mon Nov 17, 2003 6:55 pm   Post subject: (No subject)

btw, mekenzie screwed up ur dwite team name eh? ur mforce now LOL
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon Nov 17, 2003 7:01 pm   Post subject: (No subject)

what're you talking about? another dwite?
Mazer




PostPosted: Mon Nov 17, 2003 7:05 pm   Post subject: (No subject)

oh geez... why didn't anybody tell me about this?!

ok, so anybody up for another EM party?
Andy




PostPosted: Mon Nov 17, 2003 7:07 pm   Post subject: (No subject)

em? whats em? and yea dwite is on wednesday this wednesday and its cuz he just signed up today lol. he accidentally gave ur team ian's team's name when submitting it
Mazer




PostPosted: Mon Nov 17, 2003 8:13 pm   Post subject: (No subject)

oh. well, i'm sure he can change it. i sure hope they update the "Teams Registered" site soon, i hear there's gonna be a team from I.H. Ateturing Secondary School participating in the contest and that one of the guys in particular on that team is really good.

P.S. EM = Evasive Maneuvers. honestly, what else am i gonna be doing during the DWITE contest?
Andy




PostPosted: Tue Nov 18, 2003 7:19 pm   Post subject: (No subject)

lol u should seriously make it lan compatible and have it so we can have more than two players playing
Tony




PostPosted: Tue Nov 18, 2003 7:27 pm   Post subject: (No subject)

oh yeah, lol... have a dozen spaceships in that tiny EM screen shoot up each other Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mazer




PostPosted: Tue Nov 18, 2003 9:10 pm   Post subject: (No subject)

yeah... not in turing. it's already lagging on the school computers with just two people. but maybe... maybe it's cuz i keep using my hadoken all the time....
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: