Another thread by the master coder xerco!

Are you feeding these lines in one at a time? If you are, it looks like you need to recalculate things like numSpaces, spaceRatio etc every time you take a new input.

You're working out the number of stops to add based on the first string that you entered, which may have a a different number of spaces and characters. :)

If you're having trouble working out the maths of it, I'd try and work out exactly step by step how it should work on paper, then stick a break point on and step through each loop checking that your code does the same. :)
 
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.
 
Back
Top Bottom