Function calling issue

Hello I'm new to C++ and was hoping to find some advice/tutoring with an issue I'm having. This is a homework code however I'm really just looking for help to understand what I'm doing wrong. I was doing well until we got to functions and I seem to have a hard time with it. Any assistance would be greatly appreciated.

I receive the following 2 errors when debugging:
warning C4244: 'initializing' : conversion from 'time_t' to 'unsigned int', possible loss of data
error C2082: redefinition of formal parameter 'flip'

Code Below
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
Description: Program simulates a coin toss. When you call the function , it should generate a random number in the range of 1 through 2.  
If the random number is 1 the display should say “heads”. If the random number is 2 the display should say “tails”. 
Program will ask the user to select how many times the coin should be tossed. Then loop the correct number of times and display the results.
Limitations or issues: 
Credits: Not Applicable
*/
#include <iostream>
#include <cstdlib> //for rand and srand
#include <ctime>   //for time function
using namespace std;

int coinFlip(int);		//function prototype

int main()
{
	int tosses, count;	//Variables defined
	count = 0;

	cout << "How many tosses should I make?" << endl;		//ask for user input
	cin >> tosses;

	
	while (count <= tosses)   //run loop while less than tosses inputed
	{
		cout << coinFlip << endl;
		count++;		
	}
system("pause");
return 0;					//end code
}
	int coinFlip(int flip)	//flip function
	{	
		unsigned seed = time(0);  //get system time
		srand (seed);			//Seed the random number generator
	
		int flip = 1 + rand() % 2;	//calculates either 1 or 2
			if (flip == 1)
			{
			cout << "Heads!.\n";  // display heads if 1
			}

			else if (flip == 2)
			{
			cout << "Tails!.\n";  //display tails if 2
			}
		return flip;
	}
The error is because you're passing a variable called flip into your coinFlip function, and then trying to declare another variable with the same name inside of the function. The warning is just because time_t numbers can go below zero but an unsigned int cannot.
Okay I changed the function name and no longer receive any debugging warnings or errors. However I must be missing something within the code that I just can't see. When the code is ran I receive the following:
How many tosses should I make?
6
01171023
01171023
01171023
01171023
01171023
01171023
01171023
Press any key to continue . . .

instead of: eg.
How many tosses should I make?
3
Heads!
Tails!
Tails!
Here's the code now:
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
Description: Program simulates a coin toss. When you call the function , it should generate a random number in the range of 1 through 2.  
If the random number is 1 the display should say “heads”. If the random number is 2 the display should say “tails”. 
Program will ask the user to select how many times the coin should be tossed. Then loop the correct number of times and display the results.
Limitations or issues: 
Credits: Not Applicable
*/
#include <iostream>
#include <cstdlib> //for rand and srand
#include <ctime>   //for time function
using namespace std;

int coinFlip(int flipFunc);		//function prototype

int main()
{
	int tosses, count;	//Variables defined
	count = 0;

	cout << "How many tosses should I make?" << endl;		//ask for user input
	cin >> tosses;

	
	while (count <= tosses)   //run loop while less than tosses inputed
	{
		cout << coinFlip << endl;
		count++;		
	}
system("pause");
return 0;					//end code
}
	int coinFlip(int flipFunc)	//flip function
	{	
		unsigned seed = time(0);  //get system time
		srand (seed);			//Seed the random number generator
	
		int flip = 1 + rand() % 2;	//calculates either 1 or 2
			if (flip == 1)
			{
			cout << "Heads!.\n";  // display heads if 1
			}

			else if (flip == 2)
			{
			cout << "Tails!.\n";  //display tails if 2
			}
		return flip;
	}

At this point I've missed the deadline for passing it in I'm just getting bothered that I can't figure this out. Any suggestions would be great Thanks
cout << coinFlip << endl;
That's not how you call a function. You need the parenthesis and the int parameter (which is unused and should be removed :P)
cout << coinFlip(1337) << endl;
ok thanks I fixed that and it all seems to work but it seems to always pick Heads or Tails unless I enter 100 tosses for example does that seem right?
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
#include <iostream>
#include <cstdlib> //for rand and srand
#include <ctime>   //for time function
using namespace std;

int coinFlip();		//function prototype
const int HEADS = 1;
const int TAILS = 2;
int main()
{
	int tosses, count;	//Variables defined
	count = 0;
	cout << "How many tosses should I make?" << endl;		//ask for user input
	cin >> tosses;
	
	while (count <= tosses)   //run loop while less than tosses inputed
	{	coinFlip();
		count++;		
	}
system("pause");
return 0;					//end code
}
	int coinFlip() //flip function
	{	
		srand((unsigned)time(0));			//Seed the random number generator
	
	int flip = (rand()%2)+1;	//calculates either 1 or 2
		//cout << flip << endl;	//testing
	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 

eg.

How many tosses should I make?
7
Heads!.
Heads!.
Heads!.
Heads!.
Heads!.
Heads!.
Heads!.
Heads!.
Press any key to continue . . .
well you are seeding it every time you call the function

1
2
3
4
int coinFlip() //flip function
	{	
		srand((unsigned)time(0));			//Seed the random number generator
....


just seed it once in the start of your main function
great thanks for all the help!
Topic archived. No new replies allowed.