Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Chances of stopping
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.

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

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)

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....
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 15 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: