Re: A83: (A bunch of Re:s) Problem with a program


[Prev][Next][Index][Thread]

Re: A83: (A bunch of Re:s) Problem with a program




In accordance with the prophecy, Dsc984@aol.com uttered:


> Well, it seems that a lot of people have a good idea for the loop, but what 
> about the output/storing the answer?  I don't want to have to try and fool 
> around with the user lists anymore :(

> -Rangsk


If you only want the average, you're best off calculating that and displaying
it. I'd do such a program by having a variable ("x"). Then, for
every toss, change x to

[old value of x]*number_of_tosses_excluding_this_one + outcome_of_this_toss
---------------------------------------------------------------------------
                    number_of_tosses_including_this_one


Make a loop to toss a coin, display the value of the variable, then loop back
until the user interrupts the procedure. If the value approaches 1/2, you can
conclude that the probability of getting heads is equal to the probability of
getting tails.

Of course, you'd have to include the reasoning behind this formula in your
report, but it shouldn't be hard to grasp.

Linus
============================================================================
            Actual excuse notes teachers have recieved, part 3:
              - Dear School: Please ekscuse John being absent
                on Jan. 28, 29, 30, 31, 32, and also 33.
============================================================================
lairfight@softhome.net, visit http://linusworld.cjb.net (PGP key available).



References: