Hey guys, I am having a problem with a program I created. I am trying to count the number of vowels in a string and then erase said vowels and display the new string and the amount of vowels. The value I am getting from the amount of vowels is always wrong and the new string with the vowels erased doesn't display anything. Here is the code:
#include <iostream>
#include <string>
using namespace std;
string noVowels(string);
bool isA_vowel(string);
string noVowels(string)
{
string input = "";
string VowelsErased = "";
for (unsigned int i = 0; i < input.length(); i++)
{
#include <iostream>
#include <string>
#include <cstring>
usingnamespace std;
bool IsVowel (char ch);
int main ()
{
string input;
string newstring;
cout << "Please enter a string: ";
getline (cin, input);
for (char ch : input)
{
if (!IsVowel (ch))
{
newstring += ch;
}
}
cout << "There are " << input.size() - newstring.size() << " vowel(s) in the string: " << input << endl;
cout << "The string: " << input << ", with the vowel(s) removed is: " << newstring << endl;
system ("pause");
return EXIT_SUCCESS;
}
bool IsVowel (char ch)
{
constchar vowels[] = "aAeEiIoOuU";
return strchr (vowels, ch) != 0;
}
Output:
1 2 3
Please enter a string: Louisa Lippmann
There are 6 vowel(s) in the string: Louisa Lippmann
The string: Louisa Lippmann, with the vowel(s) removed is: Ls Lppmnn