This is what i have so far.......I need to add a function named coin to simulate a coin toss where heads is represented by a 1 and tails a 2. The outcome of the toss should be printed and the result should be return to the main program. I'm having trouble figuring it out, can anyone please help?
[code=cpp]
#include <iostream>
using namespace std;
# include <ctime>
int coin();
int main ()
{
int NUM_FLIPS = 100;
int count, face, heads = 0, tails = 0;
// initialize the random number generator
srand(static_ca st<int>(time(0) ));
// generate and count the number of heads and tails
for (int count=1; count <= NUM_FLIPS; count++)
{
face = coin();
if (face == 1)
heads++;
else
tails++;
cout << face << endl;
}
cout << "The number flips: " << NUM_FLIPS << endl;
cout << "The number of heads: " << heads << endl;
cout << "The number of tails: " << tails << endl;
}[/code]
[code=cpp]
#include <iostream>
using namespace std;
# include <ctime>
int coin();
int main ()
{
int NUM_FLIPS = 100;
int count, face, heads = 0, tails = 0;
// initialize the random number generator
srand(static_ca st<int>(time(0) ));
// generate and count the number of heads and tails
for (int count=1; count <= NUM_FLIPS; count++)
{
face = coin();
if (face == 1)
heads++;
else
tails++;
cout << face << endl;
}
cout << "The number flips: " << NUM_FLIPS << endl;
cout << "The number of heads: " << heads << endl;
cout << "The number of tails: " << tails << endl;
}[/code]
Comment