[Tutor] Heads & Tails was Re: (no subject)

Alan Gauld alan.gauld at btinternet.com
Wed Oct 1 11:20:12 CEST 2008


"kayla bishop" <horses_kayla10 at hotmail.com> wrote 

Please use a sensible subject line

> I can't figure out how to write a program where you flip a 
> coin 100 times and it keeps track of how many heads 
> and tails you flipped but it has to be random. 

This sounds like homework so we cannot give you a solution.

But here are some questions that may help you find a solution:

1) could you write a program to ask the user for a head or 
a tail and store the answer?

2) could you make that program repeat 10 times and store 
the count of heads only?

3) could you store the total for heads and tails into two 
separate totals?

4) could you replace the user input with a random number?

5) could you make the random number result be one of two 
values - say head and tail?

6) could you increase the repetitions to 100?

Done all that? Then you've solved your problem.
If you didn't where did you get stuck?
Show us your code and any errors.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list