I am working on a console application that will open a file and read input data it has a date then a price such as:
01/02/2009 22.46
it'll take the highest out of the list of 20 or so then place it into the output file and then average of all of them and place it into an output file as well.
i have the following line of code for it, but i need to figure out how to ignore the 01/02/2009 and the other lines.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int LIMIT = 20;
int number = 0;
int sum = 0;
ofstream outFile;
ifstream inFile;
inFile.open("PriceHistory.txt");
if (inFile.fail())
{
cout << "Error: Failed to open input file." << endl;
exit(1);
}
for (int i = 0; i <= LIMIT; i++)
{
inFile >> number;
sum += number;
}
inFile.close();
outFile.open("PriceSummary.txt");
if (outFile.fail())
{
cout << "Error: Failed to open output file." << endl;
exit(1);
}
outFile << "Sum: " << sum;
outFile.close();
}
i'm thinking i got the for loop messed up, here is a copy of price history so you can get an idea of the file i'm trying to input.