I'm trying to make a program that accepts a user string and then counts the amount of times that each appears.
I've found that the basic word counting function should be something like this, just need help with counting the frequency of each word. Any help would be appreciated, thanks.
EDIT: this is what I have so far
#include <iostream>
using namespace std;
bool inWord(char& ch);
int main()
{
int wordCount = 0, j = 0;
int charCount[26] = {0};
char text[100];
cout << "Enter a line of text: ";
cin.getline(text,100);
while(j < 100)
{
while(inWord(text[j]))
{
++charCount[tolower(text[j]) - 'a'];
++j;
}
++wordCount;
++j;
cout << wordCount << "words\n";
for(int i = 0; i < 26; ++i)
{
if(charCount[i] != 0)
{
cout << charCount[i] << ' ' << static_cast<char>('a' + i) << endl;
}
}