Hey ladies and gents I am having a little problem with my code
here it is
Code:
#include <iostream> // cin, cout
#include <fstream> // ifstream, ofstream
#include <string> // string, getline()
#include <cassert> // assert()
#include <cfloat> // DBL_MIN and DBL_MAX
using namespace std;
int main()
{
cout << "This program computes the longest and shortest\n"
"lines in a file, as well as the average number of\n"
"characters per line.\n\n";
cout << "Enter the name of the input file: ";
string inputFileName;
getline(cin, inputFileName);
cin.get();
ifstream inStream; // to the input file,
inStream.open(inputFileName.data()); // establish connection,
// and check for success
char ch;
unsigned int i=0,line=0, minLine=0, minChars=65535, maxLine=0, maxChars=0, totChars=0;
i = 0;
ch = cin.get();
while (ch != EOF)
{ /* Read until EOF is reached */
i++; /* Count the characters*/
ch = cin.get();
if ( ch=='\n')
{
line++; /* increment when a newline is found*/
totChars += i-1; /* Correction for \n (newline) character*/
if (i<minChars)
{
minChars = i;
minLine = line;
}
else if (i>maxChars || minChars>maxChars)
{
maxChars = i;
maxLine = line;
}
i = 0;
}
}
cout << "The Input file has: "<< line <<", lines\n";
cout << "The average number of characters per line is: " << (totChars/(float)line);
cout << "Line: " << minLine <<" is the shortest line with: " << minChars << " characters\n";
cout << "Line: " << maxLine <<" is the longest line with: " << maxChars << " characters\n";
return 0;
}
it is supposed to read a txt file count the characters in each line then display the line number and length of the shortest and longest lines in the file na dthe average number of characters per line. but it just displays the first cout statement and then asks for file name and that is it. can anyone help