Good day: There have been similar posts to my question...but i don't see what I'm doing wrong. Our professor wanted us to use a switch/case statement, we started transversing a string....The assisgnment : Write a program that will read in a one line phrase from a text file named “vowels.txt”.
Output, to the screen and printer, the phrase and then the number of vowels in the phrase.
Example:
The slippery eel found no help from an outside source .
The number of vowels is 18.
Below is what I've got so far:
#include <cstring>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
int main()
{
ifstream inFile;
inFile.open ("vowels.txt");
string sentence;//sentence from inFile
char ch;
int i;
int length = 0;
while (getline(inFile,sentence))
{
cout<<sentence<<endl;
}
int numz = sentence.length();//number of vowels
for (int i = 0; i < numz; ++i)
{
ch = toupper (sentence [i]);
if (isalpha (ch) && (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'))
{
numz++;
}
}
cout<<"The number of vowels: "<<numz<<endl;
inFile.close();
return 0;
}