#include <iostream>
#include <string>
usingnamespace std;
int main ()
{
int ACounter = 0; //Counts the number of times A appears
int ECounter = 0; //Counts the number of times E appears
int ICounter = 0; //Counts the number of times I appears
int OCounter = 0; //Counts the number of times O appears
int UCounter = 0; //Counts the number of times U appears
int Total = 0; //Total amount of vowels
size_t A;
size_t E;
size_t I;
size_t O;
size_t U;
string UserInput; //String that contains UserInput
string Copy; //Copy of UserInput String
A = UserInput.find_first_of ("Aa");
E = UserInput.find_first_of ("Ee");
I = UserInput.find_first_of ("Ii");
O = UserInput.find_first_of ("Oo");
U = UserInput.find_first_of ("Uu");
cout << "Please Enter a sentence." << endl;
getline (cin , UserInput);
Copy = UserInput;
cin.sync ();
while (A != string::npos)
{
UserInput [A] = '*';
A = UserInput.find_first_of ("Aa" , A + 1);
ACounter++;
}
while (E != string::npos)
{
UserInput [E] = '*';
E = UserInput.find_first_of ("Ee" , E + 1);
ECounter++;
}
while (I != string::npos)
{
UserInput [I] = '*';
I = UserInput.find_first_of ("Ii" , I + 1);
ICounter++;
}
while (O != string::npos)
{
UserInput [O] = '*';
O = UserInput.find_first_of ("Oo" , O + 1);
OCounter++;
}
while (U != string::npos)
{
UserInput [U] = '*';
U = UserInput.find_first_of ("Uu" , U + 1);
UCounter++;
}
cout << "We have marked the vowels with asterisks (*) " << UserInput << endl;
cout << "Here is the orginal " << Copy << endl;
cout << "We found " << ACounter << " A(s)" << endl;
cout << "We found " << ECounter << " E(s)" << endl;
cout << "We found " << ICounter << " I(s)" << endl;
cout << "We found " << OCounter << " O(s)" << endl;
cout << "We found " << UCounter << " U(s)" << endl;
cout << "For a grand total of " << Total << " Vowels!" << endl;
cout << "Pause (Press ENTER to end the program)" << endl;
cin.get ();
return 0;
}
I get this output
Please Enter a sentence.
Hello World
We have marked the vowels with asterisks (*) Hello World
Here is the orginal Hello World
We found 0 A(s)
We found 0 E(s)
We found 0 I(s)
We found 0 O(s)
We found 0 U(s)
For a grand total of 0 Vowels!
Pause (Press ENTER to end the program)
A = UserInput.find_first_of ("Aa");
E = UserInput.find_first_of ("Ee");
I = UserInput.find_first_of ("Ii");
O = UserInput.find_first_of ("Oo");
U = UserInput.find_first_of ("Uu");
cout << "Please Enter a sentence." << endl;
getline (cin , UserInput);
You're searching UserInput before you get it from the user. It will always fail to find anything because it's searching an empty string.