Hi,
I got a question on the coin flip project. I got the program down right but my results show a number for each coin flip in addition to the cout that says "The coin flip shows Heads/Tails". How do I get rid of the number? It looks something like this when I run it...
The coin flipped Heads
1
The Coin flipped tails
2
The coin flipped Heads
1
The coin flipped Heads
1
The Coin flipped tails
2
1 2 3 4 5 6 7 8 9 10 11
int coin()
{
int flip;
flip= rand() % 2 + 1;// assign random numbers
if (flip == 1)
cout << "The flip was heads." << endl;
else
cout << "The flip was tails." << endl;
//end if
return (flip);
}
I can show the rest of the code if needed but I think I included the part where the problem is. Thanks.
#include <iostream>
usingnamespace std;
# include <ctime>
int coin()
{
int flip;
flip= rand() % 2 + 1;// assign random numbers
if (flip == 1)
cout << "The flip was heads." << endl;
else
cout << "The flip was tails." << endl;
//end if
return (flip);
}
int main ()
{
int NUM_FLIPS = 100;
int count, face, heads = 0, tails = 0;
// initialize the random number generator
srand(static_cast<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;
}