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 test your knowledge of: For loops Random numbers Accumulator

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 day

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!