Looping Switch problem

Hey everybody, C++ beginner here.

I'm trying to get the following code to loop back to the beginning and repeat the user input/results, but it just repeats the previous results. It will terminate properly when any character other than 'y' is entered. Any recommendations on how to reset switch values after it loops back around?

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
#include <iostream>		
#include <string>		

using namespace std;	
int main ()
{
	string input_string;
	int i;
	int aCount = 0, eCount = 0, iCount = 0, oCount = 0, uCount = 0;
	char repeat;
	
	do
	{
	cout << "Enter the sentence to be searched: " << endl;
	
	getline(cin, input_string, '\n'); 
	
	cout << "has " << input_string.length() << " characters." << endl; 
	for(i = 0; i < input_string.length(); i++)
		{
				switch(toupper(input_string[i]))
					{
					case 'A':
						aCount++;
						break;
					case 'E':
						eCount++;
						break;
					case 'I':
						iCount++;
						break;
					case 'O':
						oCount++;
						break;
					case 'U':
						uCount++;
						break;
					}
		}
			cout << "\nThere are: " << endl;
			cout << aCount << " a's," << endl;
			cout << eCount << " e's," << endl;
			cout << iCount << " i's," << endl;
			cout << oCount << " o's, and" << endl;
			cout << uCount << " u's." << endl;
			cout << "To repeat this program, enter 'y', else any key to exit: " << endl;
			cin >> repeat;
	}
	while(repeat == 'y');
}
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
#include <iostream>
#include <string>

using namespace std;
int main ()
{
	string input_string;
	int i=0;
	int aCount = 0, eCount = 0, iCount = 0, oCount = 0, uCount = 0;
	string repeat;

	do
	{
	    cout << "Enter the sentence to be searched: " << endl;

	    getline(cin, input_string, '\n');

	    cout << "has " << input_string.length() << " characters." << endl;

        switch(toupper(input_string[i]))
        {
            case 'A':
            aCount++;
            break;
            case 'E':
            eCount++;
            break;
            case 'I':
            iCount++;
            break;
            case 'O':
            oCount++;
            break;
            case 'U':
            uCount++;
            break;
        }
        cout << "\nThere are: " << endl;
        cout << aCount << " a's," << endl;
        cout << eCount << " e's," << endl;
        cout << iCount << " i's," << endl;
        cout << oCount << " o's, and" << endl;
        cout << uCount << " u's." << endl;
        cout << "To repeat this program, enter 'y', else any key to exit: " << endl;
        getline(cin, repeat);

    }while (repeat == "y");

	return 0;
}

http://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction
The problem is in getline (line 16) after formatted extraction (line 47) without extra handling.
Thank you both for taking time to reply. The link provided helped make it clear why getline is required in this instance.

Codewriter,

I ran your revision of my code and it works very well. I have just one question. If you happened to run the program, you will notice that it takes the user inputted sentence and displays the number of vowels contained. If one chooses to proceed and perform another vowel analysis, the program will display both the new vowel count as well as the old. Is there a way to 'reset' the vowel count after each iteration?

Thanks again both of you for your help!
Topic archived. No new replies allowed.