I/o Files

A file with random numbers was provided and from that, a code needs to be produced to make 3 other files (one listing all the odd numbers, one listing all the even numbers and a statistic page with the largest integer, number of even and odd numbers, sum of all numbers and average of all). I got the first two files made, but am having trouble with the statistics one. I've attempted all the procedures in the statistic file aside from average and sum of all numbers because I'm really not sure how to enter it. Thanks

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

int main()
{

ifstream inFile;
inFile.open("Random_Numbers.txt");

ofstream evenFile;
evenFile.open("even.txt");
ofstream oddFile;
oddFile.open("odd.txt");
ofstream statsFile;
statsFile.open("stats.txt");

if (inFile.fail())

{

cout << "File cannot be opened" << endl;

exit(1);

}

int num;
string item;
int count = 0;
int evenCount = 0;
int oddCount = 1;
int sum = 0;
int even = 0;
int odd = 0;
int max = 0;
int avg;
avg = sum / count;

while (!inFile.eof())

{

inFile >> num;
if (num % 2 == 0)
{
evenFile << num << endl;
}

else
oddFile << num << endl;


if (num % 2 == 0)
{

statsFile << evenCount;

}
else
statsFile << oddCount;

if (num > max)
{
max = num;
}

}

return 0;

}
Topic archived. No new replies allowed.