Counting consecutive strings in array

I need to count the number of consecutive strings in an array called source and print them out. Here is an example of the output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Enter 10 words:
aa
aa
aa
aa
bb
cc
cc
cc
cc
aa
Enter lower and upper bound:
0 9 
'aa' appeared 4 times.
'bb' appeared 1 times.
'cc' appeared 4 times.
'aa' appeared 1 times.


I have gotten my function to work mostly except the last time so it outputs the first three answers and then errors and doesn't output anything for the last.
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
#include <iostream>
#include <string>

using namespace std;
void duplicate(const string source[], int low, int high);
int main()
{
    string source[];
    int low;
    int high;
    int i;
    cout<<"Enter 10 words:\n";
    for(i=0;i<=9;i++) {
        cin>>source[i];
    }
    cout<<"Enter lower and upper bound:\n";
    cin>>low;
    cin>>high;
    duplicate(source,low,high);
    return 0;
}

void duplicate(const string source[], int low, int high) {
	int counter=1;
	int i;
	for(i=low; i<=high+1; i++) {
		counter=1;
	    while(source[i]==source[i+1]) 
		{
			counter++;
			i++;
			
		}
		cout<<"'"<<source[i]<<"'"<<" appeared "<<(counter)<<" times.\n";
		
	}
}
Line 8: Declaration of an array of strings that has no elements.

Line 14: Assigning to elements that do not exist.

Line 19: How do we know that low and high are within valid range?

Line 26: Iterate to one past high. Why?

Line 28: How far can this loop go, i.e. do all the dereferenced elements exist?
Topic archived. No new replies allowed.