C++ String Manipulating Problems

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++)
{

if ((input.substr(i,1)) == "a" || (input.substr(i,1)) == "A")
{
input.erase(i,1);
}
if ((input.substr(i,1)) == "e" || (input.substr(i,1)) == "E")
{
input.erase(i,1);
}
if ((input.substr(i,1)) == "i" || (input.substr(i,1)) == "I")
{
input.erase(i,1);
}
if ((input.substr(i,1)) == "o" || (input.substr(i,1)) == "O")
{
input.erase(i,1);
}
if ((input.substr(i,1)) == "u" || (input.substr(i,1)) == "U")
{
input.erase(i,1);
}
VowelsErased = input;
}
return VowelsErased;
}

bool isA_vowel(string)
{

string input = "";


for (unsigned int i = 0; i < input.length(); i++)
{
int numofVowels = 0;
if ((input.substr(i,1)) == "a" || (input.substr(i,1)) == "A")
{
numofVowels = numofVowels + 1;
}
if ((input.substr(i,1)) == "e" || (input.substr(i,1)) == "E")
{
numofVowels = numofVowels + 1;
}
if ((input.substr(i,1)) == "i" || (input.substr(i,1)) == "I")
{
numofVowels = numofVowels + 1;
}
if ((input.substr(i,1)) == "o" || (input.substr(i,1)) == "O")
{
numofVowels = numofVowels + 1;
}
if ((input.substr(i,1)) == "u" || (input.substr(i,1)) == "U")
{
numofVowels = numofVowels + 1;
}
return numofVowels;

}
}

int main()
{
string input;
string newstring;
cout << "Please enter a string: ";
getline(cin, input);
string VowelsErased = noVowels(input);
int numofVowels = isA_vowel(input);
cout << "There are " << numofVowels <<" vowel(s) in the string: "<< input << endl;
cout << "The string: "<< input <<", with the vowel(s) removed is: "<< VowelsErased << endl;

}

Any help is appreciated, thank you.



Your code is far to complicated:
Here is a simple demo:
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
#include <iostream>
#include <string>
#include <cstring>

using namespace 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)
{
  const char 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
Topic archived. No new replies allowed.