Use this Array in this program

How would I switch this program around so it would take this array instead of asking for the teams to enter into the tournament below?
ARRAY
string[16] = {"Texas","Ohio","Houston","Cal","AZ","Penn","Oregon","Indiana","Oklahoma","Notre Dame","Georgia State","Ohio State","UTEP","Kansas","TCU","Florida"};
PROGRAM
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
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
// This program inputs a list of team names and runs a random tournament to find the winner.
 
void print_teams(string *ptr, int size)
{
	for(int team = 0; team < size; team++)
	{
		cout << "Team "<<team<<"="<<ptr[team]<<endl;
	}
}
int main()
{
	const int NTEAMS=4;
	string *teams = new string[NTEAMS];
 
	// Get input from the user for the teams
	for(int team = 0; team < NTEAMS; team++)
	{
		cout <<"Enter the name for team #"<<team<<":";
		getline(cin, teams[team]);
	}
	print_teams(teams, NTEAMS);
 
	int teams_left = NTEAMS;
	string *team_ptr = teams;
 
	for(int round = 0; teams_left > 1; round++) {
		// Allocate space for the winners
		int new_size = teams_left/2;
		string *new_teams = new string[new_size];
		// Run a round of the tournament
		for(int team = 0; team < teams_left; team+=2) 
		{
			// Pick a winner
			int winner = rand()%2;
			//update the winners array
			new_teams[team/2] = team_ptr[team+winner];
		}
		cout << "Round "<<round<<endl;
		print_teams(new_teams, new_size);
		// Update the size and team pointer for the next round
		teams_left = new_size;
		// Free up the space for the old teams list
		delete[] team_ptr;
		team_ptr = new_teams;
	}
	system("pause");
 
}

:)
Like so:
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
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
// This program inputs a list of team names and runs a random tournament to find the winner.
 
void print_teams(string *ptr, int size)
{
	for(int team = 0; team < size; team++)
	{
		cout << "Team "<<team<<"="<<ptr[team]<<endl;
	}
}
int main()
{
	static const string available_teams[] =
	{"Texas","Ohio","Houston","Cal","AZ","Penn","Oregon","Indiana","Oklahoma","Notre Dame","Georgia State","Ohio State","UTEP","Kansas","TCU","Florida"};
	const int NTEAMS=sizeof(teams) / sizeof(teams[0]); // This evaluates the number of teams
	string *teams = new string[NTEAMS];
 
	// Get input from the user for the teams
	for(int team = 0; team < NTEAMS; team++)
	{
		teams[team] = available_teams[team];
		cout <<"Enter the name for team #"<<team<<":";
		getline(cin, teams[team]);
	}
	print_teams(teams, NTEAMS);
 
	int teams_left = NTEAMS;
	string *team_ptr = teams;
 
	for(int round = 0; teams_left > 1; round++) {
		// Allocate space for the winners
		int new_size = teams_left/2;
		string *new_teams = new string[new_size];
		// Run a round of the tournament
		for(int team = 0; team < teams_left; team+=2) 
		{
			// Pick a winner
			int winner = rand()%2;
			//update the winners array
			new_teams[team/2] = team_ptr[team+winner];
		}
		cout << "Round "<<round<<endl;
		print_teams(new_teams, new_size);
		// Update the size and team pointer for the next round
		teams_left = new_size;
		// Free up the space for the old teams list
		delete[] team_ptr;
		team_ptr = new_teams;
	}
	system("pause");
 
}
Using a vector would simplify this
Topic archived. No new replies allowed.