I need help understanding what I'm doing wrong in my coding(c++). The program should then display the number of times that team has won the World Series whenever I put a name on the team, the answer is that they have won 116 times. This happens for all the teams that I put in. I'm new in programming and I'm VERY confused. Would you please help me or explain to me what I'm doing wrong?
Here is my code:
#include <iostream>
#include <array>
#include <fstream>
using namespace std;
int main()
{
//variables
string teams, winners;
string TeamsList[200] = {};
string WinnersList[200] = {};
int counter = 0;
//open file Teams
ifstream teamsFile;
teamsFile.open("Teams.txt");
//If it does not open display "error"
if(!teamsFile){
cout << "error" << endl;
return 0;
}
// If it does open display the content of the file
cout << "Team won World Series: \n";
while (getline(teamsFile, teams)){
cout << teams << endl;
}
//close file
teamsFile.close();
//ask for a input
cout << "Enter team name to see if win World Series: \n";
getline(cin, teams);
bool found = false;
// Search for the input
for (int i = 0; i < winners.size(); i++){
if(TeamsList[i] == teams){
found = true;
break;
}
}
//open the winners file
ifstream winnersFile;
winnersFile.open("WorldSeriesWinners.txt");
// If it does not open display "error"
if(!winnersFile){
cout << "error" << endl;
return 0;
}
// If it does open count the number of times that the team won
while(getline(winnersFile, winners)){
if(winners == winners)
counter++;
}
//display result
cout << teams << " has won the world series " << counter << " times. \n ";
winnersFile.close();
return 0;
}