Output is blank

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.

Divide the letters by linecount to find average.

But it's not working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
using namespace 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;
}
Last edited on
while (current && '.' || current && '!' || current && '?') //checks each line
Can you explain in words what this check should be doing?
Topic archived. No new replies allowed.