Wrong looping reading through

Hi,
I am new to C++. I am just learning. I wrote a program that shows the repeated letters in a string (I also have to count how many times it the letter gets repeated). The thing is when I run my code to get the repeated letters from the sentence. It runs okay for some but not some. For example: "hi there" runs good returning h and e, but something like "people are nice" returns peeeeee. Point the problem out to me please. I assumed it had to do with the looping but can't figure it out exactly.

void repeatWord(string sentence)
{
for(int i=0; i<sentence.length(); i++)
for(int j=i+1; j<sentence.length(); j++)
if((!isspace(sentence[i]))&&(sentence[i] == sentence[j])){

cout<<sentence[i]<<endl;
}
return;
}
You print out a letter every time you find a repeated one. Since there are multiple pairs of e's, you print many e's.
Topic archived. No new replies allowed.