In: Computer Science
In C++ 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 times each side of the coin appears. Print the results. 0 represents tails and 1 for heads.
#source code in c++
#include<iostream>
#include <ctime>
#include <random>
using namespace std;
int main(){
srand(time(0));
int tail_count=0;
int head_count=0;
for(int i=0;i<100;i++){
int r=rand()%2;
if(r==0){
tail_count=tail_count+1;
cout<<"tail"<<endl;
}
if(r==1){
head_count=head_count+1;
cout<<"head"<<endl;
}
}
cout<<"head-count:"<<head_count<<endl;
cout<<"tail-count:"<<tail_count<<endl;
return 0;
}
#source code and output:
#if you have any doubt or more information needed comment below...i will respond as possible as soon..thanks...