/*
4. 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 return 0 for tails and 1 for heads.
*/
#include
#include
#include
using namespace std;
int main()
{
int heads=0;
int tails=0;
int toss;
srand(time(0));
for (int counter = 1; counter <= 100; counter++)
{
toss = 1 + rand() % 2;
if (toss == 1)
heads = heads + 1;
else
tails = tails + 1;
}
cout <<"number of heads: " <
cout <<"number of tails: " <
return 0;
}
2007-04-28
20:56:16
·
2 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design