Coin Toss Code using RAND

I am getting an error code
Error 2 error C2082: redefinition of formal parameter 'flip'
when I try to build and run my program. Any advice on where I am going wrong here?


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
40
41
42
43
44
45
46
47
  //CHAPTER SIX PROGRAMMING CHALLENGE EIGHT
#include <iostream>
#include<ctime> //FOR RAND AND SRAND
#include<cstdlib> //FOR TIME FUNCTION
using namespace std;

//FUNCTION PROTOTYPE
int coinFlip(int);

const int heads = 1;
const int tails = 2;

//MAIN FUNCTION
int main()
{
	srand((unsigned)time(0)); //SEED THE RANDOM NUMBER GENERATOR

	int tosses, count;	//VARIABLE DEFINED
	count = 0;

	cout << "How many tosses should be made?" << endl;		//ASK USER FOR INPUT
	cin >> tosses;

	
	while (count <= tosses)   //RUN LOOP WHILE LESS THAN TOSSES INPUTED
	{
		coinFlip();
		count++;		
	}

system("pause");
return 0;					//END CODE
}

//FIRST FUNCTION/FLIP FUNCTION
int coinFlip()
{	
		int flip = (rand()%2)+1;	//CALCULATE EITHER 1 OR 2
		
		if (flip == HEADS)
			cout << "Heads!.\n";  //DISPLAY HEADS IF 1

		else if (flip == TAILS)
			cout << "Tails!.\n";  //DISPLAY TAILS IF 2

		return flip; //END FLIP FUNCTION
} 
In funtion prototype coinflip has 1 parameter
So, instead of int I need to place 1?
Just remove that parameter -.-) since the actual function don't have any parameter
1
2
3
4
5
6
while (count <= tosses)   //RUN LOOP WHILE LESS THAN TOSSES INPUTED
 {
	if (rand()%2 == 0) cout << "Heads!";
        else cout << "Tails!";
	count++;		
 }
Topic archived. No new replies allowed.