arrays - Count Occurrences within a for loop c++ -


i'm new c++, i'm trying count amount of times letter occurs piece of text or paragraph , stores array called frequency array.

the code below working degree, happens if user types hello frequencyarray stores 11121, if user types aaba frequency array stores 1213 don't want running total i'm wanting array store 1121 , 31. if same letter appears adds 1 array.

thanks david

#include <iostream> //for cout cin #include <string>   //for strings #include <fstream>  //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 << "enter word: ";     cin >> text;  //***************************count occurances************************      (int i(0); < text.length(); i++)     {         char c = text[i];          c = toupper(c);         c -= 65;          if (c < 26 || c >=0)         {             frequencyarray[c]++;             cout << frequencyarray[c];         }     }      system ("pause");  return(0);  }` 

if don't want running total, don't have cout << freqencyarray[c]; inside cycle counting occurrences.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -