I've written a code to remove the vowels in a sentence. It mostly seems to work, but the remove function strangely begins to ignore certain vowels, and take out the first letter upon repeating.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
bool isVowel(char ch);
void noVowel(string& line);
char a, b;
string line;
int main()
{
char end = 'y';
cout << "This program will take your input and remove the vowels. Such that \"Hey There!\" " << endl;
cout << "Becomes: \"Hy Thr!\"" << endl << endl;
while (end != '#')
{
cout << "Please enter a word or sentence:" << endl;
getline(cin, ::line);
noVowel(line);
cout << endl << ::line << endl << endl;
cout << "If you would like to enter another word or phrase enter any key." << endl;
cout << "If you would like to terminate press #" << endl;
cin >> end;
}
return 0;
}
bool isVowel(char ch)
{
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
return false;
}
void noVowel(string& line)
{
string vowels;
for (size_t i = 0; i < line.size(); i++)
{
if (isVowel(line[i]))
{
vowels += line.substr(i,1);
line[i] = '*';
}
line.erase(remove(line.begin(), line.end(), '*'), line.end());
}
}
|
Output:
This program will take your input and remove the vowels. Such that "Hey There!"
Becomes: "Hy Thr!"
Please enter a word or sentence:
There are more things in Heaven and Earth
Thr r mr thngs n Havn nd arth
If you would like to enter another word or phrase enter any key.
If you would like to terminate press #
g
Please enter a word or sentence:
If you would like to enter another word or phrase enter any key.
If you would like to terminate press #
There
Please enter a word or sentence:
hr
If you would like to enter another word or phrase enter any key.
If you would like to terminate press #.
Could somebody help me?