Help with Posting Winner

Having problems with posting which contestant is the winner for my assignment, how do I connect my void findwinner function to my main function? Thanks in advance if anyone is willing to assist.


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
#include <iostream>   
#include <fstream>
#include <string>
#include <ctime>
#include <cmath>

using namespace std;

int flipcoin();
void OpenFile(ifstream& infile);
void getjudgescore(ifstream& infile, int& judgescore);
void getphonescore(ifstream& infile, int& phonescore);
void findwinner(int judgescore1,int totalphone1,int judgescore2,int totalphone2);


int main()
{
	string textfile;
	ifstream infile;

	int judgescore = 0,
		phonescore = 0,
		judgescore1 = 0,
		totalphone1 = 0,
		judgescore2 = 0,
		totalphone2 = 0;

	double temp;


	char charin;

	const char endWord = ' ',
		endLine = '\n';


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

	srand (seed);
	winner = flipcoin();


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


	cout << endl;

	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;
		infile.open(textfile.c_str());
	}



	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;


	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;

	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;

	cout << "Processing Phone Data for Contestant 2" << endl;
	cout << "== == == == == == == == == == == == == == == == == == =" << endl;
	getphonescore(infile, totalphone2);
	cout << "Total of Phone Calls for all Regions: " << totalphone2 << endl << endl;

	cout << "Final Results Summary" << endl;
	cout << "--------------------" << endl;

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

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

	




	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,
		min,
		max;
	double average;

	infile >> value;
	cout << value << " ";
	judgescore += value;

	min = value;
	max = value;

	for (int i = 0; i < 4; i++)
	{

		infile >> value;
		cout << value << " ";
		judgescore += value;

		if (value > max)
			max = value;
		if (value < min)
			min = value;


	}
	
	judgescore = judgescore - min - max;

	average = (double)judgescore / 3.0;

	judgescore = ceil(average);



}

void getphonescore(ifstream& infile, int& phonescore)
{
	int value,
		i;
	for (int i = 0; i < 4; i++)
	{

		infile >> value;
		cout << "Phone Call for Region " << i + 1 << ": " << value << endl;
		phonescore += value;
	}


}

void findwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2)
{
	int contestant1 = 0,
		contestant2 = 0;

	if (judgescore1 < judgescore2)
	{
		cout << "Contestant 1" << endl;
			contestant2++;
	}
	else
	{
		cout << "Contestant 2" << endl;
	}

	if (totalphone1 < totalphone2)
	{
		cout << "Contestant 1" << endl;
			contestant2++;
	}
	else
	{
		cout << "Contestant2" << endl;
	}

	

}


int flipcoin()
{
	const int max = 2;
	double x = 1 + 1.0;
	int y;

	y = static_cast<int> (1 + rand() * max);
	return y;
}
Last edited on
Please use code tags:
http://www.cplusplus.com/articles/jEywvCM9/

I'm not sure what your question is - what do you mean by " connect my [...] findwinner function to my main function"?
I am trying to print out which contestant wins in either the judge or phone scores in the main function.
I don't understand where you are confused. Why not call your findwinner function from main? Maybe after line 106? Perhaps you should split the findwinner function into two functions, one for each category.
I was able to get it looking at another example, thanks anyway.
Topic archived. No new replies allowed.