Question

Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the coin 100 times, and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads. [Note: If the program realistically simulates the coin tossing, then each side of the coin should appear approximately half the time for a total of approximately 50 heads and 50 tails.]

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

/*Define and Includes */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Declare the coinflip function
int coinFlip(void);

// Main Function
int main()
{
// Declaring variables
int toss;
int numOfHeads = 0;
int numOfTails = 0;
int result=0;
// srandom process
srand(time(NULL));
// Toss Loop
for (toss = 1; toss <= 100; toss = toss + 1)
{
// Return the result of the coin flip
result=coinFlip();
// Determine heads or tails
switch (result)
{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

C++ Programming Problems
Homework Solution
$20.00
Computer Science
C++ Programming
Users
Lists
Structures
Arrays
Vectors
Functions
Elements
Members
Printing
Prototypes
Linear Search
Arrays and Vectors in C++
Homework Solution
$13.00
Computer Science
C++ Programming
Arrays
Vectors
Animals
Data Storage
Names
Items
Lists
Statements
Variables
Library Application in C++
Homework Solution
$20.00
Computer Science
C++ Programming
Library Application
Classes
Books
Members
Attributes
Statements
Conditions
Constructors
Variables
Objects
Methods
C Programming Problems
Homework Solution
$25.00
Computer Science
C Programming. Students
Courses
Average Values
Grades
Integers
Numbers
Database Systems
Points
Coordinates
Commands
ASCII Art in C++
Homework Solution
$23.00
Computer Science
C++ Programming
ASCII Art
Learning Algebra
Random Values
Buildings
Floors
Equations
Games
Winning
Lines
C++ Programming Problems
Homework Solution
$8.00
Computer Science
C++ Programming
Functions
Leaves
Trees
Loops
Levels
Numbers
Users
Iterations
Statements
Variables
Odd Values
Get help from a qualified tutor
Live Chats