Help with words,lines and vowels

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?


#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <string>


using namespace std;

bool IsVowel(char);

int main(){
int number_of_words = 0;
int number_of_lines= 0;
int lineNum=0, vowels=0;
char inChar,sentine1='.',endLine='\n';



string words;
string lines;
fstream inputstream;
inputstream.open("/Users/Owner/Documents/Documents/Hunter/Spring '14/CSCI 136/HWtwo.cpp/HWtwo.cpp/myInputFile.txt");


while (inputstream>>words)
{

number_of_words++;
}

ifstream in("/Users/Owner/Documents/Documents/Hunter/Spring '14/CSCI 136/HWtwo.cpp/HWtwo.cpp/myInputFile.txt");
std::string unused;
while(std::getline(in, unused))
{
number_of_lines++;

}

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();

return 0;
}
Here's an example of the exact program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
using namespace 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;
}


The link is below:

http://www.experts-exchange.com/Programming/Languages/CPP/Q_24641847.html
Topic archived. No new replies allowed.