Let's say the input is your two sentences as strings.
Then the first thing to do is to create two temporary strings, with all
the non-word characters eliminated (e.g. punctuation characters). Split
the sentences into string arrays by word delimiters.
Then you can assign an integer variable to score. Create an outer loop
and an inner loop for the two sentences. When the words match in the
sentences, increment the variable by 1, remove the word from the 2nd
sentence (replace the word with a non-word character) and break out of the
Also, use this operator for word comparison instead: