Home / Expert Answers / Computer Science / solve-in-c-2-coin-tosswrite-a-function-named-cointoss-that-simulates-the-tossing-of-a-coin-when-y-pa374

(Solved): Solve in C++2. Coin TossWrite a function named coinToss that simulates the tossing of a coin. When y ...



Solve in C++

2. Coin Toss

Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed and then simulates the tossing of the coin that number of times.

//DO NOT MODIFY THIS SECTION
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//Prototype
void coinToss();

int main()
{
int n,i;
srand( time( nullptr ) );
rand(); rand(); rand();

cout << "How many times? ";
cin >> n;
//ADD YOUR CODE FROM HERE



We have an Answer from Expert

View Expert Answer

Expert Answer



Here's the complete solution for the Coin Toss problem in C++ :



We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe