HI! I am reading Bjarne Stroustrup programming principles and practice using C++ 2nd. I am trying to count the repeated words. for example, if i input three same words, it should output that it repeated three times.
Your logic is a bit off here.
Every time you input a word into current it will increment num_repeated regardless of whether it was equal to previous.
What you want to do is only increment if the current word is equal to previous word. Then, as soon as the current word isn't equal to the previous word, you'll have entered a different word, so we print and then reset num_repeated.
Beware of off-by-one bug.