Author |
Message |
compudave
|
Posted: 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
|
|
|
Chimaera
|
Posted: 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
|
Posted: Wed Nov 12, 2003 8:59 pm Post subject: (No subject) |
|
|
hehe dave got it before u lol
code: | var num : real
randomize
for count : 1 .. 10
rand (num)
exit when num <= .50
put count
end for
|
|
|
|
|
|
|
nis
|
Posted: 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
|
Posted: 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
|
Posted: 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
|
Posted: Mon Nov 17, 2003 6:53 pm Post subject: (No subject) |
|
|
sutpid turing... lol |
|
|
|
|
|
Andy
|
Posted: 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
|
|
|
Mazer
|
Posted: Mon Nov 17, 2003 7:01 pm Post subject: (No subject) |
|
|
what're you talking about? another dwite? |
|
|
|
|
|
Mazer
|
Posted: 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
|
Posted: 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
|
Posted: 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
|
Posted: 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
|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Mazer
|
Posted: 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.... |
|
|
|
|
|
|