# Thread: Coinflip Simulation

1. ## Coinflip Simulation

Hello Guys ,
i have an exercise to do in C but im relly bad in C, so i need your help to solve this exercise.
Thats the exercise:
Exercise 84: Coin Flip Simulation
Whats the minimum number of times you have to flip a coin before you can have three consecutive flips that result in the same outcome (either all three are heads or all three are tails)? Whats the maximum number of flips that might be needed? How many flips are needed on average? In this exercise we will explore these questions by creating a program that simulates several series of coin flips. Create a program that uses Pythons random number generator to simulate flipping a coin several times. The simulated coin should be fair, meaning that the probability of heads is equal to the probability of tails. Your program should flip simulated coins until either 3 consecutive heads of 3 consecutive tails occur. Display an H each time the outcome is heads, and a T each time the outcome is tails, with all of the outcomes for one simulation on the same line. Then display the number of flips that were needed to reach 3 consecutive occurrences of the same outcome. When your program is run it should perform the simulation 10 times and report the average number of flips needed. Sample output is shown below:

Output:
H T T T (4 flips)

H H T T H T H T T H H T H T T H T T T (19 flips)
T T T (3 flips)
T H H H (4 flips)
H H H (3 flips)
T H T T H T H H T T H H T H T H H H (18 flips)
H T T H H H (6 flips)
T H T T T (5 flips)
T T H T T H T H T H H H (12 flips)
T H T T T (5 flips)
On average, 7.9 flips were needed.
Can someone helps me? 2. Show your attempt.

The first two questions are rather simple-mineded. Obviously the minimum is 3, and the maximum is, what, a gazillion? It's a stupid question. 3. Yeah I know a stupid Question but i have to solve it...

I think the min. and max. can you write in your program like this:
H T T T (4 flips)
H H T T H T H T T H H T H T T H T T T (19 flips)
T T T (3 flips)
T H H H (4 flips)
H H H (3 flips)
T H T T H T H H T T H H T H T H H H (18 flips)
H T T H H H (6 flips)
T H T T T (5 flips)
T T H T T H T H T H H H (12 flips)
T H T T T (5 flips)
On average, 7.9 flips were needed.
Min.: 3 flips
Max.: 19 flips

But i have no Idea HOW...

My attempt is relly bad and dont work like I want to work, thats why i need help on this project... 4. i have an exercise to do in C but im relly bad in C,
...
Create a program that uses Pythons random number generator to simulate flipping a coin several times.
Bad at spelling also!

This is a C forum. The instructions say to use the Python RNG, rather than the C version. Why do you think you should be coding the program in C! 5. Yeah sorry for my spelling im bad in english too XD.

So my teacher/Master sad that we have to do it in C cause we cant programming Phyton 6. Originally Posted by FakePlays Yeah sorry for my spelling im bad in english too XD.

So my teacher/Master sad that we have to do it in C cause we cant programming Phyton
Programmers invented spell checker programs! ;^)

Then why specify using the Python RNG???

Post your code if have some problem with your code, and ask specific questions. 7. My specific question is how can I solve this exercise What’s the minimum number of times you have to flip a coin before you can have three consecutive flips that result in the same outcome (either all three are heads or all three are tails)? What’s the maximum number of flips that might be needed? How many flips are needed on average? In this exercise we will explore these questions by creating a program that simulates several series of coin flips. The simulated coin should be fair, meaning that the probability of heads is equal to the probability of tails. Your program should flip simulated coins until either 3 consecutive heads of 3 consecutive tails occur. Display an H each time the outcome is heads, and a T each time the outcome is tails, with all of the outcomes for one simulation on the same line. Then display the number of flips that were needed to reach 3 consecutive occurrences of the same outcome.

​My code is pure trash and dont work... 8. Originally Posted by FakePlays My specific question is how can I solve this exercise My code is pure trash and dont work...
So the output you displayed above is what you expect? What is the actual output from your code?

We can't program the code for you. You have to make an attempt, and post your code so we can comment on it. Popular pages Recent additions #### Tags for this Thread

coinflip, flips, program, program c, simulation 