I am struggling to understand what I need to do to access arrays that were created within the functions I have written. I need to be able to access it so I can continue to the next part of the assignment I'm working on. In the code, I can list out the teams, enter the team name and get info on how many times they have won, but I can't access the arrays created from the text files to create a new function that then compares the arrays. Code is below. Any ideas?
#include <fstream>
#include <string>
using namespace std;
//Function prototypes
void wonOnceList(string[], int&);
void teamWinsList(string, string[], int&);
int main()
{
string teamNameEntered;
const int ARRAY_SIZE = 100; // Array size
string teamName[ARRAY_SIZE]; // Array with team names that have won at least once
string worldSeriesWinnersList[ARRAY_SIZE]; //list of winning teams from 1903 to 2012
wonOnceList(teamName[], ARRAY_SIZE);
cout << "\nEnter the name of one of the teams listed above to find out the number\n";
cout << "of times that team has won the World Series from 1903 to 2012." << endl;
getline(cin, teamNameEntered);
cout << "You entered " << teamNameEntered << endl;
teamWinsList(teamNameEntered);
return 0;
}
void wonOnceList(string teamName, int& count) {
const int ARRAY_SIZE = 100; // Array size
string teamName[ARRAY_SIZE]; // Array with 100 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object
inputFile.open("Teams.txt"); // Open the file.
// Read the team names from the file into the array.
while (count < ARRAY_SIZE && getline(inputFile, teamName[count]))
count++;
// Close the file.
inputFile.close();
// Display the teams read.
cout << "The teams that have won the World Series: \n";
for (int index = 0; index < count; index++)
cout << teamName[index] << endl;
}
void teamWinsList(string winners, string worldSeriesWinnersList[], int& ARRAY_SIZE) {
int timesWon = 0; //wins counter
const int ARRAY_SIZE = 100; // Array size
string worldSeriesWinnersList[ARRAY_SIZE]; // Array with 100 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object
inputFile.open("WorldSeriesWinners.txt"); // Open the file.
// Read the team names from the file into the array.
while (count < ARRAY_SIZE && getline(inputFile, worldSeriesWinnersList[count]))
count++;
// Close the file.
inputFile.close();
//loop determining wins per team
for (int i = 0; i < ARRAY_SIZE; i++) {
if (winners == worldSeriesWinnersList[i])
timesWon++;
}
//outputing times won per team
cout << "\nThe team " << winners << " has won the World Series ";
cout << timesWon << " times from 1903 to 2012." << endl;
}```