title: While loop causing an infinite loop but I can't figure out why
body: <p>I am working on an assignment in C++ meant to teach us more about objects and OOP. Below is my code. The gist of it is, the user enters some input, and the program counts the number of vowels or consonants (chosen by the user), the total number of characters entered, and the total number of end-of-lines.</p>
  
  <p>I am having three issues:</p>
  
  <ol>
  <li>The portion of code I've commented out is causing an infinite loop when left in. It causes the output from the <code>countChars</code> function to be printed infinitely, as well as the output asking the user if they would like to put in more input.</li>
  <li>The <code>countChars</code> function isn't counting EOL properly. I think it is most likely due to my unfamiliarity with the EOL. How do I signify it in my conditional statement? If I want to say, "increment if it has a value of '0'", I say, <code>if (variable == 0)</code>. How do I tell C++ to increment if something is an EOL?</li>
  <li><code>countChars</code> outputs random, negative values for the counts. I do notice the values changing depending on what I type (except EOL), but I am not sure why I am getting negative values. I'm not sure how to fix it beyond using an <code>unsigned int</code> and initializing the values.</li>
  </ol>
  
  <p>Also, I foresee people telling me to use the getline function, but we had very specific instructions to use <code>cin.get</code> (we're supposed to learn a bit of everything, after all) so please, avoid a fix that uses <code>getline</code>.</p>
  
  <p>Header file: </p>
  
  <pre><code>/*
  +----------------------------------------+
  |               CountChars               |
  +----------------------------------------+
  | -countVorC : Integer                   |
  | -countEOL : Integer                    |
  | -totalChars : Integer                  |
  | -vowelCount : Boolean                  |
  +----------------------------------------+
  | &lt;&lt;constructor&gt;&gt;                        |
  |   CountChars()                         |
  | +inputChars() :                        |
  | +vowelCheck(characterToCheck : Boolean)|
  | +setVowelCount(VorC : Character)       |
  | +getCountVorC() : Integer              |
  | +getCountEOL() : Integer               |
  | +getTotalChars() : Integer             |
  | +getVowelCount() : Boolean             |
  +----------------------------------------+
  */
  
  using namespace std;
  
  #ifndef COUNTCHARS_H
  #define COUNTCHARS_H
  
  class CountChars
  {
  private:
      unsigned int countVorC;
      unsigned int countEOL;
      unsigned int totalChars;
      bool vowelCount;
  public:
      CountChars();
      void inputChars();
      bool vowelCheck(char characterToCheck);
      void setVowelCount(char VorC);
      int getCountVorC();
      int getCountEOL();
      int getTotalChars();
      bool getVowelCount();
  };
  
  #endif
  </code></pre>
  
  <p>Implementation file: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;cctype&gt;
  #include &lt;cstdio&gt;
  #include "CountChars.h"
  
  using namespace std;
  
  CountChars::CountChars()
  {
      unsigned int countVorC = 0;
      unsigned int countEOL = 0;
      unsigned int totalChars = 0;
      bool vowelCount = false;
  }
  
  void CountChars::inputChars()
  {
      int letter;
  
      while ((letter = cin.get()) != EOF &amp;&amp; letter != EOF){
          if (vowelCount == true &amp;&amp; (vowelCheck(letter) == true)) {
              countVorC++;
          }
          else if (vowelCount == false &amp;&amp; (vowelCheck(letter) == false)) {
              countVorC++;
          }
  
          if (isalpha(letter)) {
              totalChars++;
          }
  
          if (letter == '\n') {
              countEOL++;
          }
      }
  }
  
  bool CountChars::vowelCheck(char characterToCheck)
  {
      characterToCheck = toupper(characterToCheck);
  
      if ((isalpha(characterToCheck)) &amp;&amp;
         (characterToCheck == 'A' || characterToCheck == 'E' ||
         characterToCheck == 'I' || characterToCheck == 'O' ||
         characterToCheck == 'U')) {
         return true;
      }
      else {
          return false;
      }
  }
  
  void CountChars::setVowelCount(char VorC)
  {
      VorC = toupper(VorC);
  
      if (VorC == 'V') {
          vowelCount = true;
      }
      else {
          vowelCount = false;
      }
  }
  
  int CountChars::getCountVorC()
  {
      return countVorC;
  }
  
  int CountChars::getCountEOL()
  {
      return countEOL;
  }
  
  int CountChars::getTotalChars()
  {
      return totalChars;
  }
  
  bool CountChars::getVowelCount()
  {
      return vowelCount;
  }
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;cctype&gt;
  #include &lt;cstdio&gt;
  #include "CountChars.h"
  
  using namespace std;
  
  void printCounts(CountChars);
  
  int main()
  {
      char VorC;
      char repeat = 'Y';
      CountChars charCounter;
  
      cout &lt;&lt; "Welcome to the Character Counter Program!" &lt;&lt; endl;
      cout &lt;&lt; "\nWould you want to count vowels or consonants?" &lt;&lt; endl;
      cout &lt;&lt; "Type 'V' for vowels and 'C' for consonants: ";
      cin &gt;&gt; VorC;
      cout &lt;&lt; endl;
  
      while (toupper(VorC) != 'V' &amp;&amp; toupper(VorC) != 'C') {
          cout &lt;&lt; "\nSorry, that was an invalid choice. Please try again: ";
          cin &gt;&gt; VorC;
          cout &lt;&lt; endl;
      }
  
  
      do {
          cout &lt;&lt; "You may being typing input below.\n" &lt;&lt; endl;
  
          charCounter.setVowelCount(VorC);
          charCounter.inputChars();
          cin.clear();
          printCounts(charCounter);
  
          cout &lt;&lt; "\nWould you like to enter new input?" &lt;&lt; endl;
          cout &lt;&lt; "Type 'Y' for yes or 'N' for no: ";
          cin &gt;&gt; repeat;
          cout &lt;&lt; endl;
  
          while (toupper(repeat) != 'Y' &amp;&amp; toupper(repeat) != 'N') {
                  cout &lt;&lt; "\nSorry, that was an invalid choice. Please try again: ";
                  cin &gt;&gt; repeat;
                  cout &lt;&lt; endl;
          }
  
      } while (toupper(repeat) == 'Y');
  
      cout &lt;&lt; "\nThank you for using the Character Counter Program!\n" &lt;&lt; endl;
  
      system("pause");
      return 0;
  }
  
  void printCounts(CountChars charCounter)
  {
  cout &lt;&lt; "\nTotal characters: " &lt;&lt; charCounter.getTotalChars() &lt;&lt; endl;
  
          if (charCounter.getVowelCount() == true) {
              cout &lt;&lt; "Total vowels: " &lt;&lt; charCounter.getCountVorC() &lt;&lt; endl;
          }
          else {
              cout &lt;&lt; "Total consonants: " &lt;&lt; charCounter.getCountVorC() &lt;&lt; endl;
          }
  
          cout &lt;&lt; "Total end-of-lines: " &lt;&lt; charCounter.getCountEOL() &lt;&lt; endl;
  }
  </code></pre>