I have a problem with a piece of code where I ask the user to type in a filename and then I need to store the number contents of the file in an array, and then use whats in the array to find the sum of the numbers, the biggest, smallest and average of the contents
I have some files with 6 or 7 numbers, or text and I need the array to just store 5 numbers and ignore the text.
// CO1401 Reassessment 2008/9
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
double max(const double *data, int N);
double min(const double *data, int N);
double sum(const double *data, int N);
double mean(const double *data, int N);
int sum()
{
double N, sum=0;
sum=sum+N;
}
int max()
{
double N, max=0;
for (double N = 0; N<6 ; N++);
}
int main()
{
string filein;
ifstream myfilein;
double N, sum=0;
int num[5];
const int NMAX = 10; // Maximum number of items to be processed
// Get the file name from the user.
cout << "Please enter the file name that you which to be processed : " << endl;
cin >> filein;
// Open the file.
do
{
myfilein.open (filein.c_str());
if (!myfilein.is_open())
{
cout << "Unable to open file, sorry!" << endl;
cout << "Please enter the file name that you which to be processed : ";
cin >> filein;
}
}
while (!myfilein.is_open());
// Read the data from the file into an array
num[5] = (filein.c_str());
//Print contents of file on screen
cout << "These are the contents of the file: " << endl;
while (myfilein.good())
cout << (char) myfilein.get();
cout << endl << endl;
// Calculate and print results on screen.
/*
To do: remember to calculate max, min,
sum and mean using functions
*/
cout << "The sum of the contents the file is: " << sum << endl;
/* cout << "The maximum value of the file is: " << max << endl;
cout << "The minimum value of the file is: " << min << endl;
cout << "The mean value of the file is: " << mean << endl;
*/
return 0;
}
/*To do - function definitions*/
Any Help would be great
Thanks Liam.