Question
Write a program in C++ that simulates a coin toss and determines if it is realistic. For each toss of the coin, the program should
Write a program in C++ that simulates a coin toss and determines if it is realistic.
For each toss of the coin, the program should print Heads or Tails.
Prompt the user to enter the number of times the coins should be tossed. The coin should be tossed at least 10 times. Include an input validation statement to enforce this request.
Count the number of times each side of the coin appears.
Your program should call a separate function that takes no arguments, but returns 0 for heads and 1 for tails.
Format your output so that 10 tosses are printed per line.
Your program will call another function to determine if the simulation was realistic. This function will accept the number of heads (or the number of tails) as well as the number of tosses as arguments.
If the selected side of the coin appears approximately half of the time, (between 45% and 55%) return true. Your code should print This simulation was realistic. Otherwise, your code should print This simulation was not realistic.
Sample Output 1
Enter the number of times you want to toss the coin: 5
The number of tosses must be greater than 10. Re-enter: 50
Tails Tails Heads Heads Heads Tails Tails Tails Heads Tails
Heads Heads Tails Heads Heads Heads Tails Tails Tails Heads
Tails Heads Heads Heads Heads Tails Tails Heads Heads Heads
Tails Tails Tails Tails Heads Tails Tails Tails Tails Heads
Tails Heads Tails Tails Tails Tails Tails Tails Heads Heads
The total number of Heads was 22
The total number of Tails was 28
This simulation is not realistic.
Sample Output 2
Enter the number of times you want to toss the coin: 30
Heads Tails Heads Heads Tails Heads Tails Tails Heads Tails
Heads Tails Heads Tails Heads Tails Heads Tails Tails Heads
Tails Heads Tails Heads Heads Heads Tails Tails Tails Tails
The total number of Heads was 14
The total number of Tails was 16
This simulation is realistic.
Step 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