Hi,
I am currently trying to create a program where I input a file called "exp.txt" that contains two columns: 1) date 2) expenses. There are 100 rows. Essentially I'm trying to read a file containing DATE-EXPENSE pairs and find the average EXPENSE between two specific Dates. Eventually, I will write the results to an output file called "final.txt". Currently, I'm having trouble writing the part where the user specifies the beginning and end date and that points to the array. Can you give me some help on where I can write the code to specify dates? Do I use the void mean() function and call that in int main()? Thanks for your input!
**********************************************************
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void bubbleSort (int[], const int);
void mean (int[], int);
int main()
{
const int arraySize = 100;
int a[arraySize];
int i, hold;
char date [10];
double expense;
ifstream inFile ("exp.txt"); // opens the input file
ofstream outFile ("final.txt");
if (!inFile) // if it is not able to open the file
{
cout << "Unable to open file" << endl;
exit (1);
}
while (date >> expense) // reads the file
{
for (i=0; i < arraySize; i++) // loop
cout << setw (10) << a[i];
}
bubbleSort (a, arraySize); // sorting the array
for (i=0; i < arraySize; i++)
cout << setw (10) << a[i];
cout << endl;
outFile.open ("final.txt");
outFile.close();
return 0;
}
void bubbleSort (int a[], int size)
{
int hold;
for (int pass = 0; pass <size -1; pass++) // passes
for (int i=0; i < size - 1; i++) // one pass
if (a[i] > a [i+1]) // then compare
{
hold = a[i];
a[i]= a[i+1];
a[i+1]= hold;
}
}
void mean (const int answer[], int size)
{
int total = 0;
for (int i = 0; i < size; i++)
total += answer[i];
}