Can't get it to Average correctly

Here is my code and it takes in a .txt file and separates the number by greater or less than 70. I need to get an average of those numbers as well. I don't know what I am dong wrong. Any help would be appreciated. I am getting like double the average I am supposed to get.
Thanks for help from anyone.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace std;

const string INPUT_FILENAME = "temps.txt";

// Opens the file specified by Filename. If the connection fails it
// returns false, else it returns true.
bool Connect2Input(string Filename, ifstream& fin);

// Displays the two counts along with their averages, one per line.
void DisplayCounts(int CountOver70, int CountBelow70,
int AveOver70, int AveBelow70);



int main()
{
int AveBelow70=0;
int AveOver70=0;
int CountOver70=0;
int CountBelow70=0;
int sum=0;
ifstream fin;

if ( Connect2Input(INPUT_FILENAME, fin) == false)
{
cerr << "Error opening file " << INPUT_FILENAME << " for reading. Aborting!"
<< endl;
exit(1);
}

int num;
fin >> num;
while ( !fin.eof() )
{
sum=sum+num;
if (num > 70)
{
CountOver70+=1;

AveOver70 = sum / CountOver70;
}
else
{

CountBelow70+=1;
AveBelow70 = sum / CountBelow70;
}

fin >> num;
}
DisplayCounts(CountOver70, CountBelow70, AveOver70, AveBelow70);
fin.close();




return (0);
} // end main()

bool Connect2Input (string Filename, ifstream& fin)
{
bool success = true;
fin.open( Filename.c_str() );
if ( fin.fail() )
{
success = false;
}

return (success);
}
void DisplayCounts(int CountOver70, int CountBelow70,
int AveOver70, int AveBelow70)
{
cout<<"Temperatures Over 70 Degrees: "<<CountOver70<<" Ave: "<<AveOver70<<endl;
cout<<"Temperatures Below 70 Degrees: "<<CountBelow70<<" Ave: "<<AveBelow70<<endl;
}
Topic archived. No new replies allowed.