1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void findLargeSmall (int, int&, int&);
void findTotals (int, int&, int&, int&);
int main () {
int count = 1, current = 0, large = 0, small = 0, total = 0, totalOdd = 0, totalEven = 0;
ifstream inFile;
ofstream outFile;
inFile.open ("myInput.dat");
outFile.open ("result.dat");
while (count <= 10) {
inFile >> current;
findLargeSmall (current, large, small);
findTotals (current, total, totalOdd, totalEven);
if (current %2 == 0)
outFile << "Even: " << current << endl;
else
outFile << "Odd: " << current << endl;
count++;
}
outFile << "Total\t" << "Total Odd\t" << "TotalEven\t" << "Largest\t\t" << "Smallest\t" << endl << endl;
outFile << total <<"\t"<< totalOdd <<"\t\t"<< totalEven <<"\t\t"<< large <<"\t\t"<< small <<"\t"<< endl;
return 0;
}
void findLargeSmall (int c, int& l, int& s) {
if (l < c)
l = c;
else;
if (s > c)
s = c;
else;
}
void findTotals (int c, int& t, int& tOdd, int& tEven) {
t += c;
if (c %2 == 0)
tEven += c;
else tOdd += c;
}
|