表达式必须是可修改的值(C)

时间:2017-04-02 08:53:20

标签: c loops expression unmodifiable

快速提问:

#include <stdio.h>

int main(void) {
    int divisor, counter, binary, counter2;
    int digit0, digit1, digit2, digit3; 
    float decimal;

    printf("Decimal\t\tBinary\n");

    for (counter = 0; counter <= 15; counter++) {
        printf("%d\t\n", counter);   

        decimal = counter;

        for (counter2 = 0; counter2 <= 3; counter2++) {
            decimal % 2 == 1 ? digit0 = 1 : digit0 = 0);
        }
    }

    return 0;
}

我继续在第二个for循环中的变量名“decimal”上得到“表达式必须是可修改的值”的错误。

为什么会这样,我该如何解决?

谢谢!

1 个答案:

答案 0 :(得分:1)

因为 let url = Bundle.main.url(forResource: "art.scnassets/half", withExtension: "dae") let sceneSource = SCNSceneSource(url: url!, options: nil) let tubeGeometry = (sceneSource?.entryWithIdentifier("Cube-mesh", withClass: SCNGeometry.self ))! as SCNGeometry tubeNode = SCNNode(geometry: tubeGeometry) tubeNode.position = SCNVector3(0, 1, 0) tubeNode.eulerAngles = SCNVector3Make(1.5, 2, 0) tubeNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: tubeGeometry, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron])) scene.rootNode.addChildNode(tubeNode) decimal,但float仅适用于整数。如果您真的想使用%进行修改,则可以使用函数float,它会计算float fmod(float x, float y),您应该包含x%y来使用它。