[Tutor] Coin toss program
dyoo at hkn.eecs.berkeley.edu
Wed Nov 5 13:00:41 EST 2003
On Wed, 29 Oct 2003, LONG, SPENCER wrote:
> "Write a program that flips a coin 100 times and then tells you the
> number of heads and tails."
> Can anyone forward to this Newbie the code for how this is accomplished?
> So far I have code that flips the coin once (using a random number
> generator), which results in either a heads or tails. But again, it's a
> single flip of the coin.
Well, one way to do this is to write one hundred lines of code flips.
*grin* But this is probably not a good way to approach the problem.
Have you read about using loops yet? Here are two links to tutorials that
talk about loops:
There are other tutorials at:
that should have more examples of loops --- as soon as you get them, you
can solve that coin-flipping program in a couple of lines (instead of one
More information about the Tutor