A counter is usally an int that counts something. An array is just a list of integers of a specific size. The following example creates an array of counters and counts the number of each vowel in a string
for (; str[0] != '\0'; str++)
if (str[0] == 'a')
counts[0]++
if (str[0] == 'e')
counts[1]++
if (str[0] == 'i')
counts[2]++
if (str[0] == 'o')
counts[3]++
if (str[0] == 'u')
counts[4]++
cout<<"Count of 'a' "<<counts[0]<<endl
cout<<"Count of 'e' "<<counts[1]<<endl
cout<<"Count of 'i' "<<counts[2]<<endl
cout<<"Count of 'o' "<<counts[3]<<endl
cout<<"Count of 'u' "<<counts[4]<<endl
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.