I'm supposed to write a program that keeps track of the hits, walks and outs of a baseball team using parallel arrays. The player number is the index of the array. Program is supposed to read text file that contains the player number, hits, walks and outs. The data file contains multiple games. Not every player has stats to each game.
Here is the text file:
2
1 2 2 2
20 0 5 1
2 0 0 6
18 4 2 0
3 2 1 3
4 1 2 3
7 0 0 3
8 1 4 1
9 3 2 1
10 2 2 2
11 6 0 0
12 2 2 2
2 0 5 1
20 0 0 6
17 4 2 0
4 2 1 3
1 2 2 2
3 1 2 3
7 0 0 3
And here is my code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main ()
{
const int noOfPlayers = 21;
int playerNo [noOfPlayers] = {0};
int hitsNo[noOfPlayers]={0};
int walksNo[noOfPlayers]={0};
int outsNo[noOfPlayers]={0};
int player = 0;
int hits = 0;
int walks =0;
int outs = 0;
ifstream infile;
infile.open ("PlayBall.txt");
while (infile)
{
for (int game =1; game < noOfPlayers; game++)
infile >> playerNo [player] >> hitsNo [0+hits]++
>> walksNo [0+walks]++ >> outsNo [0+outs]++;
}
cout << setw(8) << "Player" << setw (8) << "Hits" << setw(8) << "Walks"
<< setw(8) << "Outs" << endl;
cout << endl;
for (int playerNo = 1; playerNo < noOfPlayers; playerNo++)
{
cout << setw(8) << playerNo [noOfPlayers] << setw(8)
<< hitsNo [noOfPlayers] << setw(8) << walksNo [noOfPlayers]
<< setw(8) << outsNo [noOfPlayers]<< endl;
}
infile.close();
return 0;
}
I don't know what's wrong but compiler is giving me an error message: "ambiguous overload for std::basic_istream<char,
std::char_traits<char> >& >> int operator
Please help

New Topic/Question
Reply




MultiQuote






|