Coin Flip Output help

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.
closed account (z05DSL3A)
My guess is that the number is output from the calling function.
Here's the full code if it helps.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace 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;
}
closed account (z05DSL3A)
Line 33!
cout << face << endl; Delete it.
Last edited on
Thanks Wolf.
Topic archived. No new replies allowed.