in Roman numbers a situation where you have a lower value proceeding a higher value like "IV" you subtract. In the case of "IV" you subtract I = 1 from V = 5 to get four. The current and next variables are created to evaluate just this condition. If condition is found then do the math and set the new result. Seeing as you used two of the strings, you need to advance one to begin the next evaluation. Notice that next is i+1. If you don't advance after the subtraction eval then the loop count will fall one behind and the math is wrong. Hope this helps.
Because if the current symbol is smaller than the next one, for instance, 'CM', it means that the number is 900 (100 subtracted from 1000). Therefore, the index must jump one place ahead of the current symbol so that the loop avoids mistakenly including the 'M' from 'CM' in the addition. I hope it makes sense.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
why i++ in the if condition ?
in Roman numbers a situation where you have a lower value proceeding a higher value like "IV" you subtract. In the case of "IV" you subtract I = 1 from V = 5 to get four. The current and next variables are created to evaluate just this condition. If condition is found then do the math and set the new result. Seeing as you used two of the strings, you need to advance one to begin the next evaluation. Notice that next is i+1. If you don't advance after the subtraction eval then the loop count will fall one behind and the math is wrong. Hope this helps.
Because if the current symbol is smaller than the next one, for instance, 'CM', it means that the number is 900 (100 subtracted from 1000). Therefore, the index must jump one place ahead of the current symbol so that the loop avoids mistakenly including the 'M' from 'CM' in the addition. I hope it makes sense.