# Thread: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

1. Member
Join Date
Oct 2011
Posts
34
Rep Power
0

## Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

Removing my code.
Last edited by scd250; 11-02-2011 at 10:44 PM.

2. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

Java Code:
```    // step 2:
// initialize all of the values in the array to 0

counts[count] = 0;
}```
Just a little point while I read the code... The condition in that for loop doesn't look right. It's quite possible to get maxHeads heads so that entry in the counts array should also be initialised to zero.

Eg, suppose the user wanted ten flips per trial. In that case you have to have space to record eleven possible outcomes for a trial: 0,1,2,3,4,5,6,7,8,9,10 heads.

Also, I'm wondering what happens if you omit step 2. (besides upsetting the teacher)

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

Java Code:
```    // step 3:
// flip the coin for n sets with nFlips flips per set
// count the number of heads in each set (heads = 1, tails = 0)

for (int s = 0; s < nSets; s++){
int sum = 0;
for (int f = 0; f <nFlips; f++){
sum = sum +(myCoin.flip()? 1:0);

}
}```
For set s you obtain the number of heads, sum. But shouldn't you do something with sum once you have calculated it? Hint: yes you must, otherwise you have no data to send to the histogram in step 5.

Also note that your counts array entries which you made zero, stay zero because you never change them. This explains the problem you started the thread with (the zero probabilities.) ANd it suggests what you might do with sum once you have calculated it.
Last edited by pbrockway2; 10-30-2011 at 07:30 AM.

4. Member
Join Date
Oct 2011
Posts
34
Rep Power
0

## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

sdfasdfasfasdf
Last edited by scd250; 11-07-2011 at 08:19 AM.

5. Member
Join Date
Oct 2011
Posts
34
Rep Power
0

## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

asdfasdfasdfasdfasf
Last edited by scd250; 11-07-2011 at 08:19 AM.

6. ## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

Read line #5 of your code again; I don't think the loop condition makes sense ...

kind regards,

Jos

7. Member
Join Date
Oct 2011
Posts
34
Rep Power
0

## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

I can't see it :/

8. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

You are saying count>nFlips in the loop.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•