More than that, the algorithm as pasted only adds an additional single space for each pre-existing space, if it thinks it needs to put any in.
That will never satisfy the last line which requires several spaces inbetween the 2 words.
You started off on the right track with looking to see how many 'spaces per space' you need, but I'm not sure that modulo is the right way to do it or that you've got the variables either side of the modulo operator in the right order anyway (I think of ratio is being numerator divided by denominator, not as the remainder value, so I suspect it's division you want not the mod).
Finally, you've decided at the beginning of the program what your spaces to add and space ratio is going to be, and they remain fixed from the first sentence to the last, when they should be recalculated for each sentence that is incoming. Think about how those values are set from the first sentence, and then how that could ever work on the last sentence without updating those values to be applicable to the different text and word counts / line lengths.