So I need to make a program that counts the number of words, lines, and vowels in a program. Punctuation and white spaces are not counted in any of the counts. I have this so far and the words, and lines work and are correct but I can't seem to get the vowel count to work. Any advice?
while (!inputstream.eof())
{
inputstream.get(inChar);
if (inChar !=sentine1)
{
if (inChar!=endLine)
{
switch(inChar)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vowels++;
default:;
}
}
else
lineNum++;
}
}
cout<<"Number of vowels: "<<vowels<<endl;
vowels=0;
cout<<"Number of words: " << number_of_words << endl;
cout<<"Number of lines: "<< number_of_lines<<endl;
inputstream.close();
#include<iostream>
usingnamespace std;
int main()
{
int n[256]={0}; // an array to hold the count of all characters entered
int consonants=0,vowels=0,characters=0; // number of consonants, vowels, words & characters
char user_input[255]; // the user input
cout<<"Enter a string:"<<endl;
cin.getline(user_input,255); // get the user input
cout<<"You entered: "<<user_input<<endl;
for(int c=0;user_input[c]!='\0';++c) // loop through the entire user input
{
++n[user_input[c]]; // add 1 to the array holding the count of each character
}
vowels=n['A']+n['a']+n['E']+n['e']+n['I']+n['i']+n['O']+n['o']+n['U']+n['u'];
consonants=n['B']+n['b']+n['C']+n['c']+n['D']+n['d']+n['F']+n['f']+n['G']+n['g']+n['H']+n['h']+n['J']+n['j']+n['K']+n['k']+n['L']+n['l']+n['M']+n['m']+n['N']+n['n']+n['P']+n['p']+n['Q']+n['q']+n['R']+n['r']+n['S']+n['s']+n['T']+n['t']+n['V']+n['v']+n['W']+n['w']+n['X']+n['x']+n['Y']+n['y']+n['Z']+n['z'];
characters=n['A']+n['a']+n['B']+n['b']+n['C']+n['c']+n['D']+n['d']+n['E']+n['e']+n['F']+n['f']+n['G']+n['g']+n['H']+n['h']+n['I']+n['i']+n['J']+n['j']+n['K']+n['k']+n['L']+n['l']+n['M']+n['m']+n['N']+n['n']+n['O']+n['o']+n['P']+n['p']+n['Q']+n['q']+n['R']+n['r']+n['S']+n['s']+n['T']+n['t']+n['U']+n['u']+n['V']+n['v']+n['W']+n['w']+n['X']+n['x']+n['Y']+n['y']+n['Z']+n['z'];
cout<<"This has "<<characters<<" characters, "<<vowels<<" vowels and "<<consonants<<" consonants"<<endl; // data type
cin.get();
return 0;
}