I'm getting the error "no matching function for call to readProgrammers" how can I fix this?
this is the main.cpp file I also have a .h file the declares all the functions
#include <iostream>
#include <string>
#include <fstream>
#include "programmer.h"
using namespace std;
const int MAX_PROGRAMMERS = 10;
int main()
{
Programmer programmers[MAX_PROGRAMMERS];
int numProgrammers = 0;
ifstream inputFile( "programmers.txt" ); // declares file stream and opens for input
if( inputFile.good() )
{
numProgrammers = readProgrammers( inputFile, programmers, MAX_PROGRAMMERS );
//close the input file because we are done with it
inputFile.close();
//report on programmers to console
generateProgrammerReport( cout, programmers, numProgrammers ); // cout passed as an ostream
//report on programmers to a file
ofstream outputFile("ProgrammerReport.txt");
generateProgrammerReport( outputFile, programmers, numProgrammers );
outputFile.close();
}
else
{
cout << "File not opened properly!!\n\n";
}
system("pause");
return 0;
}
this is the programmer.cpp file. This is the file that has the error in the generateProgrammerInfo function when I am trying to call the function readProgrammers.
#include "programmer.h"
#include "sstream"
#include "iomanip"
//implement functions here!
//returns the number of programmers - fills in the programmers array from the ifstream
int readProgrammers( ifstream& inputFile, Programmer programmers[], int maxProgrammers )
{
int numProgrammers = 0;
int programmer_id;
string name;
int lines;
if(inputFile.is_open())
{
while (!inputFile.eof() && numProgrammers < maxProgrammers)
{
inputFile >> programmers[numProgrammers].programmer_id;
inputFile >> programmers[numProgrammers].name;
inputFile >> programmers[numProgrammers].lines;
numProgrammers++;
}
}
//just a stub!
return numProgrammers;
}
//returns the total of the lines field for all programmers
int calcTotalLines( Programmer programmers[], int numProgrammers )
{
int totalLine = 0;
for (int i = 0; i < numProgrammers; i++)
{
totalLine += programmers[i].lines;
}
//just a stub!
return totalLine;
}
//returns the average lines coded for all programmers as a float
float calcAverageLines( Programmer programmers[], int numProgrammers )
{
int totalLine = calcTotalLines(programmers, numProgrammers);
int averageLines = 0;
averageLines = totalLine/numProgrammers;
//just a stub!
return averageLines;
}
//return a string containing info for a particular programmer
string generateProgrammerInfo( Programmer theProgrammer )
{
ifstream inputFile;
Programmer programmers;
int MAX_PROGRAMMERS;
readProgrammers( inputFile, programmers, MAX_PROGRAMMERS );
int numProgrammers;
int programmer_id;
string name;
int lines;
const int SPACING = 5;
stringstream sout;
sout << setw(SPACING) << theProgrammer.programmer_id << " " << theProgrammer.name << " " << theProgrammer.lines << endl;
//just a stub!
return sout.str();
}
//generate report for all programmers
//call calcTotalLines, calcAverageLines, and generateProgrammerInfo functions
void generateProgrammerReport( ostream& output, Programmer programmers[], int numProgrammers )
{
Programmer theProgrammer;
generateProgrammerInfo(theProgrammer);
calcTotalLines(programmers, numProgrammers);
calcAverageLines(programmers, numProgrammers);
//just a stub!
output << "These are all the programmers:" << endl;
for( int i = 0; i < numProgrammers; i++ )
{
output << generateProgrammerInfo(theProgrammer); //this should output the programmer info for each programmer
}
output << "\nTotal lines = " << calcTotalLines(programmers, numProgrammers); //this should ouptut the total lines
output << "\nAverage lines = " << calcAverageLines(programmers, numProgrammers); //this should output the average lines
output << endl;
}
This is the programmer.h file
#ifndef __lab2__programmer__
#define __lab2__programmer__
#include <string>
#include <fstream>
using namespace std;
struct Programmer
{
int programmer_id;
string name;
int lines; // lines of code programmed
};
//function prototypes
//returns the number of programmers - fills in the programmers array from the ifstream
int readProgrammers( ifstream& inputFile, Programmer programmers[], int maxProgrammers );
//returns the total of the lines field for all programmers
int calcTotalLines( Programmer programmers[], int numProgrammers );
//returns the average lines coded for all programmers as a float
float calcAverageLines( Programmer programmers[], int numProgrammers );
//return a string containing info for a particular programmer
string generateProgrammerInfo( Programmer theProgrammer );
//generate report for all employees
void generateProgrammerReport( ostream& output, Programmer programmers[], int numProgrammers );
#endif /* defined(__lab2__programmer__) */
I can't change the main.cpp file or the programmer.h file.