简单数学iOS?

Sim*_*iwi 0 math integer equation objective-c

所以在我的应用程序中,我试图在我的一种方法中进行简单的数学运算,而不使用大量的if/else语句.

所以我有一个名为'StartInt'的整数,最大值为13.现在我需要得到的是FinishInt一个整数,它将是这个模式的结果:

StartInt: 13 FinishInt: 1  
StartInt: 12 FinishInt: 2 
StartInt: 11 FinishInt: 3
Run Code Online (Sandbox Code Playgroud)

等等......直到StartInt为1且FinishInt为13.无论如何,我将如何实现这一目标?我知道这一定很简单,但我在数学方面并不是那么棒!:)

Cal*_*leb 6

一路下来,直到StartInt为0,FinishInt为13.无论如何,我怎么做到这一点?

如果startInt = 13给出finishInt = 1并且你想要finishInt为每个减量增加1,这将不会很有效startInt.看看下表:

13   1
12   2
11   3
10   4
 9   5
 8   6
 7   7
 6   8
 5   9
 4  10
 3  11
 2  12
 1  13

所以你在序列的开头或结尾都是1.不过,看起来你想要这样的东西:

(int) calculateFinish(int startInt)
{
    int finishInt = -1;
    if (startInt >= 0 && startInt <= 13) {
        finishInt = 14 - startInt;
    }
    return finishInt;
}
Run Code Online (Sandbox Code Playgroud)

这会给一个14值finishIntstartInt = 0.