I am trying to write a program that reads in a line of text and counts the number of words and the number of instances of each letter. After you type in a line of text you hit return and it should give your output. Sometimes if there are some small words, three or less letters, you will need to hit return a second time. It doesn't count all small words. Also the letter count is always the same:
The number of each letter you typed in is:
I had it print out 'c' right after the cin.get statement and it seems to be reading in only every other letter. Any help will be greatly appreciated. Thank you in advance.
using namespace std;
//Explains what the program does.
void input_count_output(int& num_words);
//Asks user to input text from the keyboard and then counts
//and outputs to the screen the number of words and the number
//of each letter typed in.
int num_words = 0;
cout << "This program will ask the user to input a line of text\n"
<< "and then will output the number of words and the number of\n"
<< "each type of letter.\n"
void input_count_output(int& num_words)
cout << "Please enter a line of text, then press return:\n";
if (!cin.get(c)) //breaks if character is not able to be read in
c = tolower(c);
++letter_count[c - 'a'];
if (c == '\n' || c == '\t' || c == '"' || c == ',' || c == ';' || c == ':' || c == '.' || c == '?' || c == '!' || c == ' ')
}while(c != '\n');
//now for output
cout << "The number of words you typed in is "
<< "The number of each letter you typed in is:\n";
for (int i = 0; i < 26; i++)
if (letter_count[i] > 0)
c = 'a' + i;
cout << c
<< " "