My goal is to write a C++ program that can read a text file and:
* Count the average number of letters per sentence (the sentences end with ., ! or ?).
* Count the total amount of digits.
The text file would be read with command "./a.out < textfile"
I don't understand why the output is blank.
While the loop runs, it should check each character. If it's a letter, add to the letter count; if it's a number, add to the number count; if it's a ., ! or ?, add to the linecount.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
usingnamespace std;
int main()
{
int letters; //Total number of letters
int digits; //Total number of digits
double sentencecount; //Number of sentences
float averageletters; //Average number of letters per sentence
int linecount=0; //Count of lines
char current; //Current character
cin.get(current);
while (cin) //while receiving input
{
digits = 0;
letters = 0;
linecount++;
while (current && '.' || current && '!' || current && '?') //checks each line
{
if (isalpha(current))//counts alphabet characters
letters++;
if (isdigit(current))//counts digits
digits++;
cin.get (current);
}
sentencecount = letters/linecount;
cout << "avg number of letters" << sentencecount << "digits" << digits << endl;
cin.get (current);
}
return 0;
}