Hello;
I keep getting a erroe saying assertion debug failed. Why doesn't this give me the max and min, etc..?
When I enter name of input file: test1.dat
with data such as
11
12
13
14
15
and when it says the name of the ouput file: test1.out. I press enter and the error poops (I mean pops) up. Strange! Can anyone please explain why?
It should read something like 5 values ranging from 11 to 15 and its average.
BTW here is my code:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <cfloat>
using namespace std;
int main()
{
cout << "This program computes the number, maximum, minimum, and\n"
"average of an input list of numbers in one file,\n"
"and places its results in another file.\n\n";
// input section
cout << "Enter the name of the input file: ";
string inputFileName;
getline(cin, inputFileName);
ifstream inStream;
inStream.open(inputFileName.data());
assert(inStream.is_open());
int count = 0;
double reading,
maximum = DBL_MIN,
minimum = DBL_MAX,
sum = 0.0;
for(;;)
{
inStream >> reading;
if(inStream.eof()) break;
count++;
sum += reading;
if (reading < minimum)
minimum = reading;
if (reading > minimum)
maximum = reading;
}
inStream.close();
// output section
cout << "Enter the name of the oputput file: ";
string outputFileName;
getline(cin, outputFileName);
ofstream outStream(outputFileName.data());
assert(outStream.is_open());
outStream << "\n--> There were " << count << " values.";
if (count > 0)
outStream << "\n\tranging from " << minimum
<< " to " << maximum
<< "\n\tand their average is " << sum / count
<< endl;
outStream.close();
cout << "Processing complete.\n";
return 0;
}