2. Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a method with no parameters that randomly returns either the String "heads" or the string "tails". Call this method in main as many times as requested and report the results. See Example outputs below. Example Outputs How many times should I toss the coin? 1000 Results of 1000 tosses. Heads: 483, tails: 517 How many times should I toss the coin? 1000000 Results of 1000000 tosses. Heads: 500074, tails: 499926

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 15PE
icon
Related questions
Question

Please add comments!

 

thank you and have a good one!

2. Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a method with no parameters that randomly
returns either the String "heads" or the string "tails". Call this method in main as many times as requested and report the results. See Example outputs below.
Example Outputs
How many times should I toss the coin? 1000
Results of 1000 tosses.
Heads: 483, tails: 517
How many times should I toss the coin? 1000000
Results of 1000000 tosses.
Heads: 500074, tails: 499926
Transcribed Image Text:2. Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a method with no parameters that randomly returns either the String "heads" or the string "tails". Call this method in main as many times as requested and report the results. See Example outputs below. Example Outputs How many times should I toss the coin? 1000 Results of 1000 tosses. Heads: 483, tails: 517 How many times should I toss the coin? 1000000 Results of 1000000 tosses. Heads: 500074, tails: 499926
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning