Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Theory And Applications 27th Australasian Database Conference Adc 20 Sydney Nsw September 28 29 20 Proceedings Lncs 9877

Authors: Muhammad Aamir Cheema ,Wenjie Zhang ,Lijun Chang

1st Edition

3319469215, 978-3319469218

More Books

Students also viewed these Databases questions

Question

How is the number of factors decided in most EFA programs?

Answered: 1 week ago