return value type does not match the function type

I am playing catchup for a C++ class I am taking. I was able to get the errors from 12 down to the final two which appear below.

return value type does not match the function type
'printStats': 'void' function returning a value

Here is my code. I hope someone can give me a hand.

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

/*functions */
int loadArrays(int[], int[], int[], int[], int[]);
void calcBatAvg(int[], int[], int[], int);
void printStats(int[], int[], int[], int[], int[], int[], int);


int main(int argc, const char * argv[]) {

const int SIZE = 20;
int playerNum[SIZE], atBats[SIZE], hits[SIZE],
runs[SIZE], rbis[SIZE], batAvg[SIZE],
numberOfPlayers;

numberOfPlayers = loadArrays(playerNum, atBats, hits, runs, rbis);

/*This will calculate each player's batting average and store the results in
the batAvg array. The batting average is computed by dividing hits
by a player's at bats. This will result in a percent and then multiply the result
by 1000 and round to the nearest integer to get the integer
batting average.*/

calcBatAvg(hits, atBats, batAvg, numberOfPlayers);

printStats(playerNum, atBats, hits, runs, rbis,
batAvg, numberOfPlayers);
return 0;
}


int loadArrays(int player[], int bat[], int hit[], int run[], int rbi[])
{
int count = 0;
ifstream statsIn;
statsIn.open("baseballStats.txt");
if (statsIn.fail()) {
// This alerts the user if there is a problem opening the file.
cout << "Error opening the file\n";
return 0;
}
while (statsIn >> player[count]
>> bat[count]
>> hit[count]
>> run[count]
>> rbi[count]) {
count++;
}
statsIn.close();
return count;
}

//This is where the batting average is calculated.
void calcBatAvg(int hits[], int bats[], int batAvg[], int count) {
for (int i = 0; i< count; i++) {
batAvg[i] = (hits[i] * 1000 / bats[i]);
}
}


//These are the numbers that the Coach is looking for to include the batting average.
void printStats(int player[], int bat[], int hit[], int run[], int rbi[], int batAvg[], int count)
{

cout << "Player Num" << "\t" << "At Bat" << "\t" << "Hits" << "\t" << "Runs" << "\t" << "Bat \
Avg" << endl;

for (int i = 0; i < count; i++) {
cout << player[i] << "\t" << bat[i] << "\t" << hit[i] << "\t" << run[i] << "\t" << rbi[i]\
<< "\t" << batAvg[i] << endl;
}
return 0;

}
Hi,

Get rid of the return 0; at the very bottom of your code.
Thanks! That removed the return value error.
Now, when I run it I'm getting a Cannot find or open the pdb file.

Any suggestions? I know where it's stored. On my desktop in a file called C++ Projects.
Last edited on
Cannot find or open the pdb file.


You don't need the pdb files to run the programme. It contains debug information of use to debuggers. It should happily run without it.
^^^ but if you can't resolve this quickly, build a release compile and it will stop looking for it.
I fixed the pdb issue but I get Error Opening the File message and then the window closes.
Last edited on
statsIn.open("baseballStats.txt");

^^^^
put in the path to the file OR move the file to the folder that contains the executable (or the path from which it is invoked if not the same).
That worked! Thanks!
Registered users can post here. Sign in or register to post.