Call function from void

Having problems calling void findwinner into main function. Any help will be appreciated.

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include <iostream>				// listing all header files
#include <fstream>
#include <string>
#include <ctime>
#include <cmath>

using namespace std;

int flipcoin();					// flipcoin used for ties
// used to show and get average of judge scores
void getjudgescore(ifstream& infile, int& judgescore);
// used to show and add phonescores
void getphonescore(ifstream& infile, int& phonescore);
// used to show which contestant is the winner
void findwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2);


int main()
{
	string textfile;			// textfile name is stored here
	ifstream infile;

	int judgescore = 0,			// judge and phone scores labeled here
		phonescore = 0,
		judgescore1 = 0,
		totalphone1 = 0,
		judgescore2 = 0,
		totalphone2 = 0,
		contestant1 = 0,
		contestant2 = 0;

	double temp;				// used for average judgescore




	// intro message
	cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
	cout << "Welcome to Tallahassee Idol!  Where Stars are Born!!!" << endl;
	cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;


	cout << endl;
	// asking for file
	cout << "Enter the name of the file (no blanks!) -> ";
	cin >> textfile;
	cout << endl;
	infile.open(textfile.c_str());

	while (!infile)
	{
		cout << endl;
		cout << "The file name you gave is invalid.  Please try again." << endl;
		cout << "Enter the name of the file(no blanks!) -> ";
		cin >> textfile;
		cout << endl;			// loop for incorrectly entered file
		infile.open(textfile.c_str());
	}


	// judge scores for contestent 1
	cout << "Processing Judge Data for Contestant 1" << endl;
	cout << "== == == == == == == == == == == == == == == == == == =" << endl;
	cout << "Judge Scores are: ";

	getjudgescore(infile, judgescore1);
	cout << endl;

	cout << "Average Judge Scores are: " << judgescore1;
	cout << endl;
	cout << endl;

	// phone scores for contestent 1
	cout << "Processing Phone Data for Contestant 1" << endl;
	cout << "== == == == == == == == == == == == == == == == == == =" << endl;
	getphonescore(infile, totalphone1);
	cout << "Total of Phone Calls for all Regions: " << totalphone1 << endl << endl;

	cout << endl;
	// judge scores for contestant 2
	cout << "Processing Judge Data for Contestant 2" << endl;
	cout << "== == == == == == == == == == == == == == == == == == =" << endl;
	cout << "Judge Scores are: ";
	getjudgescore(infile, judgescore2);
	cout << endl;
	cout << "Average Judge Scores are: " << judgescore2 << endl;

	cout << endl;
	// phone scores for contestant 2
	cout << "Processing Phone Data for Contestant 2" << endl;
	cout << "== == == == == == == == == == == == == == == == == == =" << endl;
	getphonescore(infile, totalphone2);
	cout << "Total of Phone Calls for all Regions: " << totalphone2 << endl << endl;
	// which contestant is the winner
	cout << "Final Results Summary" << endl;
	cout << "--------------------" << endl;

	cout << "Judges winner is: ";
	findwinner;
	cout << findwinner << endl;
	cout << "Phone Call Winner is: ";
	cout << findwinner << endl;

	cout << endl;

	cout << endl << endl << endl << endl << endl << endl;





	// closing message
	cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
	cout << "Thanks for visiting our show!!!" << endl;
	cout << "Execution Terminated Normally." << endl;
	cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
	cout << endl;






	return 0;

}


void getjudgescore(ifstream& infile, int& judgescore)
{

	int value,			// identify min max value and average variable
		min,
		max;
	double average;

	infile >> value;				// input and shows values from data
	cout << value << " ";
	judgescore += value;

	min = value;
	max = value;

	for (int i = 0; i < 4; i++)
	{
		// loop to select each piece of data
		infile >> value;
		cout << value << " ";
		judgescore += value;

		if (value > max)			// setting min and max
			max = value;
		if (value < min)
			min = value;


	}
	// gets rid of the highest and lowest values
	judgescore = judgescore - min - max;
	// get average
	average = (double)judgescore / 3.0;
	// ceiling value of average
	judgescore = ceil(average);



}

void getphonescore(ifstream& infile, int& phonescore)
{
	int value,
		i;
	for (int i = 0; i < 4; i++)
	{
		// values of phone scores with loop for each one
		infile >> value;
		cout << "Phone Call for Region " << i + 1 << ": " << value << endl;
		phonescore += value;
	}


}

void findwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2)
{

	cout << "\n*******************************... " << endl;
	cout << " Results Time " << endl;
	cout << "Final Results Summary" << endl;
	int winner1 = 0;//no of advantage points got by contestant 1 
	int winner2 = 0;//no of advantage points got by contestant 2 
	if (judgescore1 > judgescore2)
	{
		cout << "Judges Winner is Contestant 1 " << endl;
		winner1++;
	}
	else if (judgescore1<judgescore2) {
		cout << "Judges Winner is Contestant 1" << endl;
		winner2++;
	}
	else if (judgescore1 == judgescore2)
		cout << " Judge SCore is Tied";

	if (totalphone1> totalphone2)
	{
		cout << "Phone Call Winner is Contestant 1" << endl;
		winner1++;
	}

	else if (totalphone2 > totalphone1)
	{
		cout << "Phone Call Winner is Contestant 2" << endl;
		winner2++;
	}
	else if (totalphone2 == totalphone1)
		cout << " BOTh Candidates have got equal Telephone Votes";

	if (winner1 > winner2) //compare the Advantage Points 
		cout << "Contestant 1 is the overall winner!";
	else if (winner2 > winner1)
		cout << "Contestant 2 is the overall winner!";
	else
	{
		//Both Candidates have got equal Lead Points , Time to Allow Lady Luck to determine 
		cout << "Contestants are tied!!" << endl;
		cout << "We will now flip a coin to see who wins." << endl;
		cout << "*********************************... ";
		int winner = flipcoin();	 // this function is called if the contestants tie 

		if (winner == 1)	 // if the coin rolls a 1, contestant 1 wins 
			cout << "Contestant 1 winner!" << endl << endl;
		if (winner == 2)	 // if the coin rolls a 2, contestant 2 wins 
			cout << "Contestant 2 is winner!" << endl << endl;



	}
}

int flipcoin()
{

	int winner;
	int contestent = 1;
	unsigned int seed;
	seed = static_cast<unsigned>(time(NULL));

	srand(seed);
	winner = flipcoin();


	const int max = 2;
	double x = 1 + 1.0;
	int y;
	// only used if there is a tie between contestant 1 and 2
	y = static_cast<int> (1 + rand() * max);
	return y;
}
Last edited on
Hi @rm5393,
there are missing
the (4 integers)parameters needed by
findwinner
function
void findwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2);

1
2
3
4
5
6
7
//main

cout << "Judges winner is: ";
	findwinner; //<---- missing parameters
	cout << findwinner << endl; //<---- ?
	cout << "Phone Call Winner is: ";
	cout << findwinner << endl; //<---- ? 
Last edited on
I have that exactly on my function, here is the part cut out from my code.

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
48
49
50
51
52
53
54
55
56
57
58
void getfindwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2)
{

	cout << "\n*******************************... " << endl;
	cout << " Results Time " << endl;
	cout << "Final Results Summary" << endl;
	int winner1 = 0;//no of advantage points got by contestant 1 
	int winner2 = 0;//no of advantage points got by contestant 2 
	if (judgescore1 > judgescore2)
	{
		cout << "Judges Winner is Contestant 1 " << endl;
		winner1++;
	}
	else if (judgescore1 < judgescore2) 
	{
		cout << "Judges Winner is Contestant 1" << endl;
		winner2++;
	}
	else if (judgescore1 == judgescore2)
		cout << " Judge Score is Tied";

	if (totalphone1> totalphone2)
	{
		cout << "Phone Call Winner is Contestant 1" << endl;
		winner1++;
	}

	else if (totalphone2 > totalphone1)
	{
		cout << "Phone Call Winner is Contestant 2" << endl;
		winner2++;
	}
	else if (totalphone2 == totalphone1)
		cout << " Both Candidates have got equal Telephone Votes";

	if (winner1 > winner2) //compare the Advantage Points 
		cout << "Contestant 1 is the overall winner!";
	else if (winner2 > winner1)
		cout << "Contestant 2 is the overall winner!";
	else
	{
		//Both Candidates have got equal Lead Points , Time to Allow Lady Luck to determine 
		cout << "Contestants are tied!!" << endl;
		cout << "We will now flip a coin to see who wins." << endl;
		cout << "*********************************... ";
		int winner = flipcoin();	 // this function is called if the contestants tie 

		if (winner == 1)	 // if the coin rolls a 1, contestant 1 wins 
			cout << "Contestant 1 winner!" << endl << endl;
		if (winner == 2)	 // if the coin rolls a 2, contestant 2 wins 
			cout << "Contestant 2 is winner!" << endl << endl;



	}

	return;
}
Your function call must
match with your function
prototype/implementation

for instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

//function prototype
void f(int number); //integer parameter needed        

int main(){

int num=10;
//function call
f(num); //integer parameter: num

return 0;
}//end of main

//function implementation
void f(int num){
   cout<<num<<endl;
}
my function does not have those guidelines to follow like other void functions for some reason it is pulling the values out of other void functions.
I matched my function prototype but now it only spits out the winner of the judges scores and not the phone. Also at the end of the winner of the Judge Score it adds a zero.
Topic archived. No new replies allowed.