Code two functions to fill an array with the names of every World Series winning team from 1903 to 2020, then output each World Series winner and the number of times the team won the championship
Code two functions to fill an array with the names of every World Series winning team from 1903 to 2020, then output each World Series winner and the number of times the team won the championship. The input file is attached, along with a main function and screen print. Please note team names that include two words, such as Red Sox, have an underscore in place of the space. This enables you to use the extraction operator with a single string variable.
My program is not working can you help me figure out who to make it run?
It needs to contain these specific things
- Code a function to fill an empty array
- Fill an array from an input file
- Search the array for specific elements
- Output specific array elements as part of a string
- Use a for loop to step through an array
- Use a for loop to count occurrences in an array
- Use a conditional statement within a for loop used to process an array
- Use input stream objects
- Use string objects
I attached the world series winners list and a preview of how the program should look
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
void fill (string teams[], int size);
void findWinner (string teams[], int size);
int main ()
{
const int SIZE = 118;
int lastIndex;
string team[SIZE];
fill (team, SIZE);
findWinner (team, SIZE);
return 0;
}
fstream fin ("WorldSeriesWinners.txt", ios::in);
void fill (string teams[], int size){
int i;
for (i = 0; i < size; i++) {
cin >> teams[i];
}
}
void findWinner (string teams[], int size){
char c;
do {
int i, year = 1903, count = 0;
string team;
cout << "Enter team:";
cin >> team;
transform (team.begin (), team.end (), team.begin () );
for (i = 0; i < size; i++){
transform (teams[i].begin (), teams[i].end (),teams[i].begin () );
if (teams[i].compare (team) == 0);
{
cout << team << " won the World Series in " << year << endl;
count++;
}
year++;
}
if (count == 0)
cout << team << " never won a World Series" << endl;
cout << "Run another search? (y/n): ";
cin >> c;
}
while (c == 'y');
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images