Respuesta :
Answer:
#include <iostream>
#include <cstdlib>
using namespace std;
int t;
char HeadsOrTails(){
char a='h';
char b='t';
if(t%2==0)
return a;
else
return b;
}
int main ()
{
int n, c, b;
cout << "Enter the number of decisions you want" << endl;
cin >> n;
b=1;
cout << "Decisions are:" << endl;
srand(100);
for (c = 1; c <= n; c++)
{
t = rand();
if(HeadsOrTails()=='h'){
cout<<b<<".heads"<<endl;
b++;
}
else{
cout<<b<<".tails"<<endl;
b++;
}
}
return 0;
}
Explanation:
random number generator is used to generate a number and then heads and tails is decided on even and odd number basis. if number is even then decision is head and if number is odd then decision in tails
The program is an illustration of random module.
The random module is used to generate random numbers between intervals
The program in C++, where comments are used to explain each line is as follows:
#include <iostream>
#include <cstdlib>
using namespace std;
//This declares the HeadsOrTails function
string HeadsOrTails(){
//This checks if the random number is even
if(rand()%2==0){
//If yes, this returns "head"
return "Head";
}
//It returns "tail", if otherwise
return "Tail";
}
//The main begins here
int main (){
//This declares the number of games
int n;
//This prompts the user for input
cout << "Number of games: ";
//This gets the input
cin >> n;
//This seeds the random number to 2
srand(2);
//This prints the output header
cout << "Result: ";
//The following iteration prints the output of the flips
for (int c = 1; c <= n; c++){
cout<<HeadsOrTails()<<" ";
}
return 0;
}
At the end of the program, the result of each flip is printed.
Read more about similar programs at:
https://brainly.com/question/16930523