title: C++ vector and string, count vowels
body: <p>This program supposed to read a text and count the number of vowels and consonants.  it should ignore any non alphabetic characters.  the result should me something like this:</p>
  
  <pre><code>Enter your text: I have to TURN this..in before midnight!!
   a,  e,  i,  o,  u,  y
   1,  3,  5,  2,  1,  0
  There are 19 consonants.
  </code></pre>
  
  <p>but the result from my code is :</p>
  
  <pre><code>Enter your text: I have to TURN this..in before midnight!!
   a,  e,  i,  o,  u,  y
   1,  3,  4,  2,  0,  0
  There are 31 consonants.
  </code></pre>
  
  <p>I dont know what is happening!! Also this is an assignment and I have to use all these functions and I cannot add or remove them! I read couple of other ways to count and display the numbers but unfortunately the template was given... </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  // FUNCTION PROTOTYPES GO HERE:
  void init_vectors(vector&lt;char&gt; &amp; vowels, vector&lt;int&gt; &amp; frequencies);
  string read_text(const string &amp; prompt);
  bool is_alphabetic(const char character);
  void create_list(const string &amp; str_text, vector&lt;char&gt; &amp; vec_text);
  bool is_member(const vector&lt;char&gt; &amp; list, char character);
  int find_index(const vector&lt;char&gt; &amp; list, char character);
  int compute_vowel_freqs(const vector&lt;char&gt; &amp; text, const vector&lt;char&gt; &amp; vowels, vector&lt;int&gt; &amp; freqs);
  void display_characters(const vector&lt;char&gt; &amp; characters, const int colwidth);
  void display_freqs(const vector&lt;int&gt; &amp; freqs, const int colwidth);
  
  int main()
  {
      vector&lt;char&gt; vowels;
      vector&lt;int&gt; freqs;
      string input;
      vector&lt;char&gt; text;
      int consonants(0);
  
      const int COLUMNWIDTH = 2;
      init_vectors(vowels, freqs);
      input=read_text("Enter your text: ");
  
      create_list(input, text);
      compute_vowel_freqs(text, vowels, freqs);
  
      display_characters(vowels, COLUMNWIDTH);
      display_freqs(freqs, COLUMNWIDTH);
  
      consonants = compute_vowel_freqs(text, vowels, freqs);
      cout&lt;&lt;"There are "&lt;&lt; consonants&lt;&lt; " consonants."&lt;&lt;endl;
      return 0;
  }
  
  void init_vectors(vector&lt;char&gt; &amp; vowels, vector&lt;int&gt; &amp; frequencies)
  {
  
      for (int i(0); i&lt;6; i++) //i is loop variable
      {
          frequencies.push_back(0);
      }
      vowels.push_back('a');
      vowels.push_back('e');
      vowels.push_back('i');
      vowels.push_back('o');
      vowels.push_back('u');
      vowels.push_back('y');
  }
  
  string read_text(const string &amp; prompt)
  {
      string phrase;
      cout&lt;&lt;prompt;
      getline(cin,phrase);
      return phrase;
  }
  
  
  bool is_alphabetic(const char character)
  {
      bool alphabet;
      if ((character &gt; 'a' &amp;&amp; character &lt; 'z')||(character &gt; 'A' &amp;&amp; character &lt; 'Z'))
      {
          alphabet = true;
      }
      return alphabet;
  }
  
  void create_list(const string &amp; str_text, vector&lt;char&gt; &amp; vec_text)
  {
      for( int i = 0 ; i &lt; str_text.length() ; i++)
      {
          if(is_alphabetic(str_text[i]))
              vec_text.push_back(str_text[i]);
      }
  }
  
  bool is_member(const vector&lt;char&gt; &amp; list, char character)
  {
      bool vowel;
      for (int i(0); i&lt;list.size(); i++)
      {
          if (character == list[i])
          {
              vowel=true;
          }
      }
      return vowel;
  }
  
  int find_index(const vector&lt;char&gt; &amp; list, char character)
  {
      int index = -1;
      for(int i=0; i&lt;list.size(); i++)
      {
          if(character == list[i])
          {
              index = i;
              break;
          }
      }
      return index;
  }
  
  int compute_vowel_freqs(const vector&lt;char&gt; &amp; text, const vector&lt;char&gt; &amp; vowels, vector&lt;int&gt; &amp; freqs)
  {
      int num_cons(0);
      for(int i = 0 ; i &lt; text.size() ; i++)
      {
          int index;
          if(is_member(vowels, text[i]))
          {
              index = find_index(vowels , tolower(text[i]));
              freqs[index]++;
          }
          else
              num_cons++;
      }
  
      return num_cons;
  }
  
  void display_characters(const vector&lt;char&gt; &amp; characters, const int colwidth)
  {
      for(int i=0; i&lt;characters.size(); i++)
      {
          cout&lt;&lt;setw(colwidth)&lt;&lt;characters[i];
          if((i+1)&lt;characters.size())
          {
              cout&lt;&lt;",";
          }
      }
      cout&lt;&lt;endl;
      return;
  }
  
  void display_freqs(const vector&lt;int&gt; &amp; freqs, const int colwidth)
  {
      for(int i=0; i&lt;freqs.size(); i++)
      {
          cout&lt;&lt;setw(colwidth)&lt;&lt;freqs[i];
  
          if((i+1)&lt;freqs.size())
              cout&lt;&lt;",";
      }
      cout&lt;&lt;endl;
      return;
  }
  </code></pre>