Question
This program will test your knowledge of: For loops Random numbers Accumulator variables Avoiding integer division Calculating percentages This program will simulate flipping a coin
This program will test your knowledge of:
- For loops
- Random numbers
- Accumulator variables
- Avoiding integer division
- Calculating percentages
This program will simulate flipping a coin multiple times and keeping track of how many heads/tails have shown.
First, ask the user how many coin flips they'd like to use in this simulation.
Then, have your for-loop do all of the following:
- Generate a random number that's either 0 or 1 (0 will stand for heads; 1, tails)
- Count the number of 0's/heads while the for loop executes
Next, display summary statistics including:
- Number of tosses
- Number of heads / Percentage of heads
- Number of tails / Percentage of tails
For 10 points extra credit, ask the user if they'd like to do another simulation, and if they choose to continue, repeat the program for them. Read ahead and use a do-while loop for this.
Format your output exactly like shown below, or improve upon it. Note that the integers representing the totals are all right-justified:
output:
This program will let you enter the number of coin tosses you'd like to make, and then tell you what the heads/tails distribution is. How many tosses would you like? 5000 ***Coin Toss Results*** Flips 5000 # Heads: 2451/49.02% # Tails: 2549 / 50.98% Program ending. Have a great dayStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started