快速提问:
#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”上得到“表达式必须是可修改的值”的错误。
为什么会这样,我该如何解决?
谢谢!
答案 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
来使用它。