int main()
{
void displayTeams(string);
// Display the names of the teams listed in the "Teams.txt" file.
displayTeams("Teams.txt");
cout << "\nPlease enter the name of one of the teams on the ";
cout << "list to see how many World Series they have won: ";
getline(cin, team);
void displayWorldSeriesWinners(string);
system("pause");
return 0;
}
// ********************************************************
// The displayTeams function reads data from a file and *
// displays it on the screen. *
// ********************************************************
void displayTeams(string Teams)
{
string data; // To hold the data from the file
int count = 0; // Counter variable for the columns
// File stream object to read data from a file
ifstream inputFile;
// Open the file.
inputFile.open(Teams);
// If the file successfully opened, process it.
if (inputFile)
{
// Display a description of the file's contents.
cout << "The following teams have won "
<< "the World Series at least once:\n\n";
while (getline(inputFile, data))
{
// Format output to be left-aligned
// with a field width of 24 characters.
cout << left << setw(24);
// Display an item from the file.
cout << data;
// Increment the column counter variable.
count++;
// Determine if three columns have been displayed.
if (count >= 3)
{
// If so, end the line and begin a new row of output.
cout << endl;
// Reset the column counter variable to zero.
count = 0;
}
}
// Set the alignment back to the default setting.
cout << right << endl;
}
else
{
// Display an error message.
cout << "Error opening the file.\n";
// Exit the program.
exit(0);
}
string temp_string, team;
int team_count, number;
team_count = 0;
number = 0;
ifstream infile("WorldSeriesWinners.txt");
cout << "Choose a team from the list to see how many times they have won the world series champion \n";
getline(cin, team);
while (infile >> temp_string)
{
if (temp_string == team)
{
number++;
}
team_count++;
}
cout << "The " << team << " has won the World Series Champion " << number << " times since 1903.\n";