Hey, can anyone help me figure out why the program keeps stopping with the first letter instead of following through the string??
Code:
#include <iostream>
#include <string>
using namespace std;
bool isVowel (char);
string noVowelString (string);
int main ()
{
string str;
cout<<"Enter a sentence: ";
cin>>str;
cout<<endl;
cout<<"The sentence with the vowels removed is "<<noVowelString(str)<<endl;
system("pause");
return 0;
}
bool isVowel (char ch)
{
switch (ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return true;
default:
return false;
}
}
string noVowelString (string tStr)
{
string :: size_type len=tStr.length();
bool foundVowel = false;
string :: size_type i;
for (i = 0; i < tStr.length; i++)
{
if (isVowel (tStr[i]))
{
tStr.erase (i, 1);
foundVowel = true;
}
else
tStr = tStr.substr (i, 1);
}
return tStr;
}