Explain Arrays Please

Pages: 1234... 9
Thank you very much, I'm busying my self getting my compiler to work on my desktop.


Take a look at this and compile it.

This demonstrates multi player (supporting 20 as per the requirements), holding their funds and position. I have purposely not written the whole thing or that would defeat the whole object of this :)

I have also given some explanation for the actionOnSpace() function so I hope that helps you.

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

#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;

// declare prototypes
void intializeArrays(string param1[], int param2[], float param3[]);
int actionOnSpace();

int main()
{

	int numPlayers = 20;			// 20 players (this would be prompted to the user)
	const int maxSpace = 25;

	// for names, with some dummy test data, these would obviously be entered
	// during runtime by the players - here for testing - please see the
	// intializeArrays as i have commented out the code that clears this so 
	// that this test data isnt cleared just to show you what can be done.
	string names[20] = {
		"Michael",
		"Jill",
		"Denny",
		"Mark",
		"Dylan",
		"Debbie",
		"Ann",
		"Jack",
		"Amy",
		"Danny",
		"George",
		"Amanda",
		"Alison",
		"Kevin",
		"Tim",
		"Adrian",
		"Anthony",
		"Bjorn",
		"Tony",
		"Daniel"
	};

	float money[20];			// players money
	int boardSpace[25];			// player position

	int move, wins;				// temp for rand

	intializeArrays(names, boardSpace, money);	// initialise the variables

	// set the random seed.
	srand(time(NULL));

	for (int plrCount = 0; plrCount < numPlayers; plrCount++)
	{

		cout << endl << names[plrCount] << ", press Enter to roll the dice...";
		cin.get();

		cin.sync();	// you need this to clear out the buffer and to avoid skipping

		// loop through each player updating their positions
		move = rand() % 6 + 1;	// roll the dice

		// tell them what they rolled...
		cout << endl << "Well done " << names[plrCount] << ", you rolled " << move << " on the dice!" << endl;

		if ((move + boardSpace[plrCount]) > maxSpace) {
			// we have generated a number which exceeds the maze end. technically the game
			// would be over here now that a player has reached the end before the others??
			boardSpace[plrCount] = maxSpace;
			// do we want to add some funds?
			if (actionOnSpace() == 1) {
				// we got a 1, do a random number between 1 - 100000
				// and add it to players funds.
				wins = rand() % 100000 + 1;
				money[plrCount] += wins;
			}
		}
		else
		{
			// lets make a move, we are still going.
			boardSpace[plrCount] += move;
			// we got a 1, do a random number between 1 - 100000
			// and add it to players funds.
			if (actionOnSpace() == 1) {
				// we got a 1, do a random number
				wins = rand() % 100000 + 1;
				money[plrCount] += wins;
			}
		}

		cout << "Player " << plrCount + 1 << " ("<<names[plrCount]<<") is at position " << boardSpace[plrCount] << " and has $" << money[plrCount] << " funds." << endl;

	}

	return 0;
}

// Dummy function to simulate a 1 to allow
// testing of code - see your pdf
int actionOnSpace()
{
	return 1;

	// from what i read you do a rand here to either get 0 or 1
	// if 1 you open up the good.txt file or 0 the bad.txt file

	// those txt files have a list of 20 messages in each

	// you then rand a number between 1 to 20 and create a loop
	// using that number to pick out the message. i.e. if you
	// rand 10 it would loop and display the 10th message in
	// that text file.

	// it then returns the first rand (1 or 0) back to the caller
	// which in your case is main (ive simulated a 1 here)

}


// clear out the arrays
void intializeArrays(string param1[], int param2[], float param3[])
{
	// i could have used memset here to clear out the memory 
	// but it wants you to use loops etc so here goes.

	for (int i = 0; i < 20; i++) {
//		param1[i].clear();	// names (disabled as i populated some test data)
		param3[i] = 0;		// money
	}
	
	for (int i = 0; i < 25;  i++)
		param2[i] = 0;		// positions

}


Quite a large example i know, but it shows a full example of how to store money, players and positions for 20 players.


EDIT: corrected a spelling mistake in the names list... picky picky lol
Last edited on
wont compile - giving me
C:\C++\Project 2>g++ -c help.cpp
help.cpp:7:63: error: expected constructor, destructor, or type conversion befor
e ';' token
help.cpp: In function 'int main()':
help.cpp:48:23: error: variable or field 'intializeArrays' declared void
help.cpp:51:18: error: 'srand' was not declared in this scope
help.cpp:62:15: error: 'rand' was not declared in this scope

C:\C++\Project 2>

sorry there was a typo in there, plus i forgot to include #include <stdlib.h>

That should sort it out (hopefully) - i edited the original post. I use Visual Studio 2013 so shouldn't be that much difference and it compiles ok here.


Last edited on
that fixed the rand but the intializeArrays is still give errors

C:\C++\Project 2>g++ -c help.cpp
help.cpp:9:63: error: expected constructor, destructor, or type conversion befor
e ';' token
help.cpp: In function 'int main()':
help.cpp:50:42: error: 'intializeArrays' was not declared in this scope

C:\C++\Project 2>
fixed it you did put void void intializeArrays(string param1[], int param2[], float param3[]); here the first time.
Last edited on

yeah thats the sign of getting tired :D
Alright lets see if i can make sense of this oh master of programming.
(*side note i thought global variable were to be defined outside of the main function or does it not matter in this example*)

1) I use my getPlayerNames function to fill in names for string names[20] = {}

2) Mian( define variable used)

3)Call*am i using correct term* the intializeArrays(names, boardSpace, money)

4)Dice rolls do-hicky --> For( runs dice first)

5)if statement that checks if anyone has won

6) if statement that uses function actionOnSpace to randomly deal on money and good or bad doc output as well

7)Adds that to said player "bank"

8)else( if game not over then add money this way assuming #5 came out false)

9) end of loop - this part confused me when i ran program it seem to only go through 1 loop there by not "finishing" the game but this could be ammended to loop until someone hit the last space in the boardSpace array right?

10) int actionOnSpace() is defined

11)void intializeArrays if define, followed by in mine by other functions.

Ok so that's the flow. this example will defiantly help me build the int main() especially with the running totals and so forth, but im still confused on how to set up the functions in tandem with the arrays. Meaning i dont understand how they link together.

This is how i feel right now : http://imgur.com/pn6QtWt
Did i do the action space 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
int actionOnSpace()
{
	result = rand() % 1 +1;
	
	ifstream input;
	
	//Open the input file
	if( rand = 1)
	{
		input.open("good.txt");
		
		lists = rand() % 20+1;
			if( lists = rand){
			getline(rand);
				if(!input){
				cout << "inInfo.txt could not be accessed!" << endl;
				return 0;}
				}}
	else( rand = 0)
	{
		input.open("bad.txt");
		lists = rand() % 20+1;
			if( lists = rand){
			getline(rand);
				if(!input){
				cout << "inInfo.txt could not be accessed!" << endl;
				return 0;}
				}}
}
	
1. You ask how many players and then take names for the number of players (if going by the pdf)
2. All except the 3 mentioned global ones are in main
3. Initialize should be called at the start of any fresh game.
4. Yes
5. Yes
6. Yes
7. Yes
8. Yes
9. Bingo!
10. & 11 - not sure what you mean here :-)

Well you have come far just off today sofar so dont knock youself :-)

Ok so further questions!


1) How to make loop repeat , do while loop maybe or just change something with existing for loop?
2) 10&11 is just stating where i would place the rest of the functions useing in program
3) if const int numPlayers <= 20; is a global constant listed in pdf how am i to adjust it to the cin >> numPlayers or whatever. i called a friend and hes stuck on this too.
Last edited on


1) You are correct, you can use a do..while loop instead of a for loop. An example is below and will compile but wont do much.. it just serves as a example of layout...

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

#include <iostream>
using namespace std;

// const global variables
const int maxPlayers = 20;
const int maxBoardSpace = 25;

int main()
{

	// so when we initialised our arrays we can
	// use the consts instead.

	string names[maxPlayers];
	float money[maxPlayers];
	int boardSpace[maxBoardSpace];

	int numPlayers = 0;					// provided at runtime.
	int PlayerNumber = 0;				// currently playing player.
	bool GamePlaying = true;			// this is set to false when game ends with winner
	bool NewGame = true;				// used for testing if we want to play again.

	
	// you would also need to put this logic inside another loop so that the user is asked
	// does he/she want to play again and can loop around again... like below

	do
	{

		// Initialise variables here.. remember we have new ones
		// PlayerNumber, NewGame and GamePlaying which now need 
		// to be reset.

		// ask number of players here

		do
		{
			// do your game logic in here.. and when someone reaches end of the board
			// update their money etc then set GamePlaying to false;  because its false
			// the do.. while will jump out and end.

			// so in a nutshell your saying loop while GamePlaying is true.

			// ............. done all the game logic, prepare for next player in loop

			// increae for the next player, this is a counter moving through the 
			// players 1 by 1 (what the for loop in my example was doing for us)
			PlayerNumber++;
			// trap if we go past the number of players playing 
			if (PlayerNumber > numPlayers)
				PlayerNumber = 0;

		} while (GamePlaying);

		// we get here when someone has reached the end.. we can then display results. 
		// and ask do they want to play again....

		cout << "Game Over, do you want to play again?";
		//---- etc setting NewGame to true if we want to play again otherwise false

	} while (NewGame);

}


3. maxPlayers and numPlayers are two different variables. The numPlayers would be provided when you ask at the start of the game such as

How many players will be playing?


the result would be stored in numPlayers provided it doesn't exceed maxPlayers otherwise you would prompt the user telling them "too many players". So basically the const maxPlayers is used as a reference to check against and setup the arrays, and consts cannot be modified during runtime.



Last edited on
Alright i did alittle practice program, it doesnt have any functions just the arrays but i think i can scavenge parts of it for the overall project.
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
#include <iostream>
#include <cstdlib>
#include <ctime>
//Random diceRoller Generator 
using namespace std;


int main()
{
	string playerColors[3] = {"Blue", "Purple","Yellow"};
	int boardSpace [3] = {0};
	bool pastFifteen = false;
	unsigned seed = time(0); 
	srand(seed);
	
	int diceRoll;
	cout << endl << endl;
	do
	{
		
		for(int x=0; x<3; x++) // loop to allow each playerto have one turn
			{
				cout << playerColors[x] << ", Press Enter to Roll the Die! \n";
				cin.get();
				diceRoll = rand()%6+1; // Generate a number between 1 and 6
				cout << " You rolled a " << diceRoll <<"!\n";
				boardSpace[x] = boardSpace[x] + diceRoll;
				cout << "You are now on boardspace " << boardSpace[x] << "!\n\n";
				if(boardSpace[x] >15)
				{
					pastFifteen = true;
					break;
				}
			}
			cout << "--------------------------------------------------\n";
	
	}while(!pastFifteen);
	
	cout << "--------------------------------------------------\n";
	cout << "--------------------------------------------------\n";
	for(int x=0; x <3; x++)
	{
		if(boardSpace[x] > 15)
		{
			cout << plyerColors[x] << " WON THE GAME!!";
		}
	}
	cout << "--------------------------------------------------\n";
	cout << "--------------------------------------------------\n";
	
	cout << endl << endl;
return 0;
}

Your on the right track, nice one.

This is what i have in my program so far, still missing a function and so forth. How bad is it. I haven't gotten enough yet to compile i think.
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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <string>
#include <fstream>
//Random diceRoller Generator 
using namespace std;

void intializeArrays(string param1[], int param2[], float param3[]);
void getPlayerNames(int, string[names]);

const int numPlayers = 20;
const int boardSize = 25;
int actionOnSpace();

string names[20] = {}; // Im confused on how to string the entered names here.

int main()
{

	string names[] = {0};
	bool pastFifteen = false;
	unsigned seed = time(0); 
	int move, winnings, lists;
	float money[20];
	int boardSpace[25];
	srand(seed);
	
	cout << endl << endl;
	do
	{
		
			for (int plrCount = 0; plrCount < numPlayers; plrCount++)
		{

			cout << endl << names[plrCount] << ", press Enter to roll the dice...";
			cin.get();
			cin.sync();	

			move = rand() % 6 + 1;	
			
			cout << endl << "Well done " << names[plrCount] << ", you rolled " << move << " on the dice!" << endl;

			if ((move + boardSpace[plrCount]) > boardSize) {
				
				boardSpace[plrCount] = boardSize;
				if (actionOnSpace() == 1) 
				{
					winnings = rand() % 100000 + 1;
					money[plrCount] += winnings;
				}
			}
			else
			{
				boardSpace[plrCount] += move;
				if (actionOnSpace() == 1) 
				{
					winnings = rand() % 100000 + 1;
					money[plrCount] += winnings;
				}
			}

		cout << "Player " << plrCount + 1 << " ("<<names[plrCount]<<") is at position " << boardSpace[plrCount] << " and has $" << money[plrCount] << " funds." << endl;

	}
		cout << "--------------------------------------------------\n";
	
	}while(!pastFifteen);
	
		cout << "--------------------------------------------------\n";
		cout << "--------------------------------------------------\n";
	for(int x=0; x <20; x++)
	{
		if(boardSpace[x] > 25)
		{
		//	cout << plyerColors[x] << " WON THE GAME!!";  <-- Not sure what variable goes here. ^^
		}
	}
	cout << "--------------------------------------------------\n";
	cout << "--------------------------------------------------\n";
	
	cout << endl << endl;
return 0;
}

int actionOnSpace()
{
	
	result = rand() % 1 +1;
	
	ifstream input;
	
	if( rand = 1)
	{
		input.open("good.txt");
		
		lists = rand() % 20+1;
			if(lists = rand){
				getline(x);
				if(!input){
				cout << "inInfo.txt could not be accessed!" << endl;
				return 0;}
				}}
	else(rand = 0);
	{
		input.open("bad.txt");
		lists = rand() % 20+1;
			if( lists = rand){
				getline(x);
				if(!input){
				cout << "inInfo.txt could not be accessed!" << endl;
				return 0;}
				}}
}

void intializeArrays(string param1[], int param2[], float param3[])
{

	for (int i = 0; i < 20; i++) {
		param1[i].clear();	// names
		param3[i] = 0;		// money
	}
	
	for (int i = 0; i < 25;  i++)
		param2[i] = 0;		// positions

}

void getPlayerNames(int; string[])
{
		int player, names;
			for(int player=0; player < number; player++)
				{ 
				cout <<"Enter"<< player+1 <<" name: ";
				gets(names[player]);
				cout <<endl;
				}  
}

Last edited on

By the way I ended up writing the whole thing in the early hours of the morning lol, still working out why I did that but meh :)

I realise you didn't want someone to simply write it for you which is why I haven't posted the code. However, if you change your mind and feel you may get some benefit out of it then please let me know.



Id love to have the code, I'm not going to copy it but id like to see how it works to see if i can figure this out. You have been a enormous help in explaining everything!

edit: mine almost compiles, except for the Actiononspce function is messed up.
Last edited on

Yeah simply copying the code would be no benefit to you, but I hope you get some benefit out of this - glad to help.

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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

// declare constants
const int maxPlayers = 20;
const int boardSpaces = 25;

// function prototypes
void getPlayerNames(int plrCount, string plrNames[]);
void initializeArrays(string plrNames[], int brdPos[], float plrMoney[]);
void printResults(string plrNames[], int brdPos[], float plrMoney[], int plrCount);
int actionOnSpace();

int main()
{

	// player arrays
	string names[maxPlayers];
	float money[maxPlayers];
	int boardSpace[boardSpaces];

	// game
	int numPlayers;				// number of players to play
	int playerNumber = 0;		// currently playing player
	int move, wins;				// used by rand for players move and wins
	int round;					// rounds (i.e. how many times have we looped back to player1)
	bool gamePlaying;			// false when theres a winner
	bool newGame;				// true if we want to play again

	// temp variable
	char temp;					// used for the play another game?

	do
	{
		// initialise arrays for new game.
		initializeArrays(names, boardSpace, money);

		// other misc initialisation.
		playerNumber = 0;		// starting at player 1
		round = 1;
		gamePlaying = true;		// we are playing

		// set seed
		srand(time(NULL));

		// welcome message

		cout << endl << "********************************************" << endl;
		cout << "* Welcome to CANDY LAND, the game of life! *" << endl;
		cout << "********************************************" << endl << endl;

		// how many are playing?  loop if lower than 1 or
		// higher than the maxPlayers!
		do
		{
			cout << "How many players will be playing today? ";
			cin >> numPlayers;

		} while (numPlayers < 1 || numPlayers > maxPlayers);
		
		cout << endl << "Thank you, we now need to get some names for each player." << endl << endl;

		// get the player names
		getPlayerNames(numPlayers, names);

		// time to play message  :)
		cout << endl << "Thank you, now its time to play... " << endl << endl;
		cout << "*** ROUND " << round << " ***" << endl;

		// game loop
		do
		{
			cout << endl << names[playerNumber] << ", press <enter> to roll the dice...";
			cin.get();
			
			// roll the dice
			move = rand() % 6 + 1;
			cout << endl << "Well done " << names[playerNumber] << ", you rolled " << move << "." << endl;

			// check our move 
			if ((move + boardSpace[playerNumber]) >= boardSpaces) {
				// we have generated a number which exceeds the end of the maze or we have
				// reached the end of the maze so end the game once we have updated the 
				// players funds etc
				boardSpace[playerNumber] = boardSpaces;		// we are set to last space on maze.
				if (actionOnSpace() == 1) {
					// we got a 1, add funds to player
					wins = rand() % 100000 + 1;
					money[playerNumber] += wins;
					cout << "$" << wins << " has been added to your funds. You now have $" << money[playerNumber] << endl;
				}
				else
				{
					// subtract from the player.
					wins = rand() % 100000 + 1;
					money[playerNumber] -= wins;
					cout << "$" << wins << " has been deducted from your funds. You now have $" << money[playerNumber] << endl;
				}
				// finish the game.
				gamePlaying = false;
			}
			else
			{
				// still playing
				boardSpace[playerNumber] += move;
				if (actionOnSpace() == 1) {
					// we got a 1, add funds to player
					wins = rand() % 100000 + 1;
					money[playerNumber] += wins;
					cout << "$" << wins << " has been added to your funds. You now have $" << money[playerNumber] << endl;
				}
				else
				{
					// subtract from the player.
					wins = rand() % 100000 + 1;
					money[playerNumber] -= wins;
					cout << "$" << wins << " has been deducted from your funds. You now have $" << money[playerNumber] << endl;
				}
			}

			// display my position after the roll.
			cout << "You are now at position: " << boardSpace[playerNumber] << endl;


			// move to next player, check if we have gone past
			// numPlayers and reset back to player 1
			
			if (gamePlaying)	// ensure we only update this if we are still playing
			{
				playerNumber++;
				if ((playerNumber + 1) > numPlayers) {	// since user entered 1 - 20 for numplayers and our array starts at 0 we add 1 for compare only.	
					playerNumber = 0;
					round++;	// increase round
					cout << endl << "*** ROUND " << round << " ***" << endl;
				}
			}

		} while (gamePlaying);

		// display result.
		printResults(names, boardSpace, money, numPlayers);

		// do i want to play again?
		do
		{
			cout << "Would you like to play again (y/n) ?";
			cin >> temp;
			temp = toupper(temp);	// make sure its uppercase befor we check it

		} while (temp != 'Y' && temp != 'N');

		// act on result.
		if (temp == 'Y')
			newGame = true;
		else
			newGame = false;

	} while (newGame);

	cout << endl << endl << "Thank you for playing, goodbye  :)";

	return 0;
}

//
//	$function:	getPlayerNames
//
void getPlayerNames(int plrCount, string plrNames[])
{
	// create a loop and get the required number
	// of names as per the number of players.
	for (int count = 0; count < plrCount; count++)
	{
		cout << "Enter name for Player " << count + 1 << ": ";
		cin >> plrNames[count];
	}
	cin.sync();		// clear the buffer to avoid skip
}

//
//	$function:	initializeArrays
//
void initializeArrays(string plrNames[], int brdPos[], float plrMoney[])
{
	for (int i = 0; i < 20; i++) {
		plrNames[i].clear();	
		plrMoney[i] = 0;
	}
	for (int i = 0; i < 25; i++)
		brdPos[i] = 0;		// positions
}

//
//	$function:	actionOnSpace()
//
int actionOnSpace()
{
	int cashResult, stringPos;
	string fileName, myMessage;
	fstream externalFile;

	// determine if this player gets some cash :)
	cashResult = (rand() % 2);	// 0 - 1

	// depending on result we open 1 of the files.
	if (cashResult == 1) {
		fileName = "good.txt";
		cout << endl << ":-)" << endl;
	}
	else
	{
		fileName = "bad.txt";
		cout << endl << ":-(" << endl;
	}

	// attempt to open file
	externalFile.open(fileName, fstream::in);
	if (externalFile.is_open())
	{
		// we have the file opened, rand a number between 1 and 20
		stringPos = rand() % 20 + 1;
		for (int count = 1; count <= stringPos; count++)
			getline(externalFile, myMessage);
	        // done with the file, close it.
	        externalFile.close();
	}
	else
		cout << "ERROR: Missing <" << fileName << "> external file - check path to file!" << endl;

	// Show the message
	cout << endl << myMessage << endl;

	return cashResult;
}

//
//	$function:	printResults()
//
void printResults(string plrNames[], int brdPos[], float plrMoney[], int plrCount)
{
	int plrIndex = 0;

	// highest earner
	float highMoney = 0;
	string highName;

	// winner
	float winMoney = 0;
	string winName;

	for (int count = 0; count < plrCount; count++)
	{
		// get highest money
		if (plrMoney[count] > highMoney) {
			highMoney = plrMoney[count];
			highName = plrNames[count];
		}
		// get the winner
		if (brdPos[count] == boardSpaces) {
			winMoney = plrMoney[count];
			winName = plrNames[count];
		}
	}

	// display the results.
	cout << endl << endl << "*** GAME OVER ***" << endl;
	cout << "The winner was " << winName << " who reached the maze end and has funds of $" << winMoney << "." << endl;
	cout << "The person with the most funds was " << highName << " who has funds of $" << highMoney << "." << endl << endl << endl;
}


There you go :)
Last edited on
The text files are formatted like this

1
2
3
OH NO, YOU STEPPED ON A NAIL!
OOPS, YOU SEEM TO HAVE STEPPED IN DOGGY DIRT!
...and so on
༼ つ◕_◕༽つ Softrix ༼ つ◕_◕༽つ Thank you ill study this and pray that i can figure it out before friday, stay tuned I may have more dumb questions.

Not a problem, good luck :)



Pages: 1234... 9