showing letters repeated

I am in a c++ problem solving course, and the following question is from past year students assignment and i am trying to solve them for my own practice.

the question states that the user should enter a number and my program should search a string and if the letters are repeated as that number i should show the repeated letter for ex. string (school to home)
user input : 2
program should show 'h' was repeated 2 times.
that was my try below but it is not working properly.
any suggestions ?.