After this program reads in a file, I want it to count all the vowels in the file and then output how many vowels there are. Right now it runs without any errors, but it always gives the number of vowels as 0. I'm guessing I need to add a for loop or something somewhere in the function?
Code:#include <iostream> #include <fstream> #include <string> using namespace std; bool isVowel(char ch); int main() { int vowel = 0; int total = 0; ifstream inFile; char inChar = ' '; string inputFile; cout << "Enter the name of the text file: "; cin >> inputFile; inFile.open(inputFile.data()); if (!inFile.is_open()) { cout << "input file did not open properly" << endl; return 1; } for (;;) { if (inFile.eof()) { break; } inFile.get(inChar); cout << inChar; } isVowel(ch); cout << " The number of vowels is " << vowel << endl; return 0; } bool isVowel(char ch) { int vowel = 0; switch(ch) { case 'A': case 'E': case 'I': case 'O': case 'U': case 'Y': case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; vowel++; default: return false; } }



LinkBack URL
About LinkBacks


