Vowel Finder Help

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
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>
using namespace 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)

Any Ideas?
Last edited on
1
2
3
4
5
6
7
	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.
Thank you! Oh my god I feel so stupid. Thank you for your time and sorry for wasting it. :)
Topic archived. No new replies allowed.