So in my app I am trying to do a simple math in one of my methods without using a ton of if/else statements.
So I have an integer named ‘StartInt’ which is at max 13. Now what I need to get is FinishInt an integer that will be the result of this pattern:
StartInt: 13 FinishInt: 1
StartInt: 12 FinishInt: 2
StartInt: 11 FinishInt: 3
etc… all the way down until StartInt is 1 and FinishInt is 13. Anyway how would I accomplish this? I know this must be simple but I am just not that great in Math! 🙂
That won’t quite work if
startInt = 13givesfinishInt = 1and you want afinishIntto increment 1 for each decrement ofstartInt. Check out the following table:So you’re off by 1 at either the beginning or end of your sequence. Nevertheless, it looks like you want something like this:
That’d give a value of 14 for
finishIntwhenstartInt = 0.