Input/Output Text File Manipulation issue!

Hi guys; I was wondering if you can tell me why my output screen for this program does not want to stay open. It only opens for a split of a second and it's gone. The program is supposed to take numbers from a input file and display and save the manipulation in the output file. Here is the program. Thanks guys......
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
//Declares Necessary Variables
ifstream infile;
ofstream outfile;
int inputNumber=0;
int highestNum=-999999;
int lowestNum=999999;
float sum=0;
float average=0;
int currentlineNum=1;
//Opens The Input File
infile.open("Input_File.txt", ios::in);
if (!infile)
{
cout << "Sorry, Can Not Open The File" << endl;
exit (1);
}
//Opens The Output File
outfile.open("Output_file.txt", ios::out);
do
{

//Loops Thru File, Until We Get To The Last Number
cout << "THE INPUT DATA FOR LINE #" << currentlineNum << " is: ";
outfile << "THE OUTPUT DATA FOR LINE #" << currentlineNum << " is: ";
for (int counter=1; counter <= 7; counter++)
{
infile >> inputNumber;
sum += inputNumber;//Calculates The Total Sum of #'s For Each Line

//Which Number Is Highest/Lowest
if (inputNumber > highestNum)
{
highestNum = inputNumber;
}
if (inputNumber < lowestNum)
{
lowestNum = inputNumber;
}
//Displays Current Number To The Output Screen
cout << inputNumber << "\t";
outfile << inputNumber << "\t";
}
//Finds The Total Average For Each Line
average = sum / 7;
cout << endl;
//Displays Data To The Output Screen
cout << "\nTHE HIGHEST NUMBER IS: " << highestNum;
cout << "\nTHE LOWEST NUMBER IS: " << lowestNum;
cout << "\nTHE TOTAL OF THE NUMBERS IS: " << sum;
cout << "\nTHE AVERAGE OF THE NUMBERS IS: " << average;
//Outfile Section....Saves Data To The Output File
outfile << endl;
outfile << "\nTHE HIGHEST NUMBER IS: " << highestNum;
outfile << "\nTHE LOWEST NUMBER IS: " << lowestNum;
outfile << "\nTHE TOTAL OF THE NUMBERS IS: " << sum;
outfile << "\nTHE AVERAGE OF THE NUMBERS IS: " << average << endl << endl;
//Resets Variables Back To Default Values
highestNum=-999999;
lowestNum=999999;
sum=0;
average=0;
currentlineNum++;
cout << endl << endl; //Places Data On New Line
}
while (!infile.eof()); //Loop Stops When Reaches The End Of File
cout << endl << endl << "\tWE HAVE REACHED THE END OF THE FILE." << endl;
outfile << endl << endl << "\tWE HAVE REACHED THE END OF THE FILE." << endl << endl;
//Closes Input And Output Files
infile.close();
outfile.close();
system ("pause");
return 0;
}
1
2
3
4
5
if (!infile)
{
cout << "Sorry, Can Not Open The File" << endl;
exit (1);
}

Probably program cannot open file and stop executing. Try to run it from command line and see if it is the case.
Topic archived. No new replies allowed.