title: Count Occurrences within a for loop c++
body: <p>I'm new to c++, what i'm trying to do is count the amount of times a letter occurs with a piece of text or paragraph and stores this into an array called frequency array.</p>
  
  <p>The code below is working to a degree, what happens is if the user types hello frequencyarray stores 11121, if the user types aaba frequency array stores 1213
  I don't want a running total i'm wanting the array to store 1121 and 31. so if the same letter appears it adds 1 to the array.</p>
  
  <p>Thanks David</p>
  
  <pre><code>#include &lt;iostream&gt; //for cout cin
  #include &lt;string&gt;   //for strings
  #include &lt;fstream&gt;  //for files
  
  using namespace std;
  
  int main()
  {       
      string text;
  
      int frequencyarray [26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  
      cout &lt;&lt; "Enter Word: ";
      cin &gt;&gt; text;
  
  //***************************COUNT OCCURANCES************************
  
      for (int i(0); i &lt; text.length(); i++)
      {
          char c = text[i];
  
          c = toupper(c);
          c -= 65;
  
          if (c &lt; 26 || c &gt;=0)
          {
              frequencyarray[c]++;
              cout &lt;&lt; frequencyarray[c];
          }
      }
  
      system ("pause");
  
  return(0);
  
  }`
  </code></pre>