Repeated Words - Bjarne Stroustrup Book

Edit: after re reading this post a couple times I discovered why "she" and "good" are not repeated. It's because she is capitalized the first time and good has a period on the second one. My bad for this post but ayy, atleast I learned :)

I've been reading and doing the lessons in Bjarne's book and have come across this exercise.

"Get the “repeated word detection program” to run. Test it with the sentence "She she laughed He He He because what he did did not look very very good good." How many repeated words were there? Why? What is the definition of word used here? What is the definition of repeated word? (For example, is She she a repetition?)"

the program he is talking about is this one:

1
2
3
4
5
6
7
8
9
10
int main()
	{
		string previous = " ";
		string current;
		while (cin >> current) {
			if (previous == current)
				cout << "repeated word: " << current << '\n';
			previous = current;
		}
}


when you run the code using his example sentence "She she laughed He He He because what he did did not look very very good good." you get these results in the console:

1
2
3
4
repeated word: He
repeated word: He
repeated word: did
repeated word: very


My question is why does the console only say those 4 words repeated when the words she and good also repeated?
Last edited on
The strings "She" and "she" do not compare equal (case-sensitive)
The strings "good" and "good." do not compare equal (different size)
Topic archived. No new replies allowed.