Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone数学不太符合逻辑_Iphone_Objective C_Arrays_Math_Integer - Fatal编程技术网

iPhone数学不太符合逻辑

iPhone数学不太符合逻辑,iphone,objective-c,arrays,math,integer,Iphone,Objective C,Arrays,Math,Integer,我在添加数组中的值,但其和实际上应该是+1 //update totalscore uint newTotalScore; for (uint i=0; i< [bestscoresArray count] ; i++) { newTotalScore += [[bestscoresArray objectAtIndex:i] intValue]; } totalscore = newTotalScore; //更新

我在添加数组中的值,但其和实际上应该是+1

//update totalscore
    uint newTotalScore;

    for (uint i=0; i< [bestscoresArray count] ; i++) {      
        newTotalScore += [[bestscoresArray objectAtIndex:i] intValue];  

    }


    totalscore = newTotalScore;
//更新totalscore
uint新核心;
对于(uint i=0;i<[bestscoresArray count];i++{
newTotalScore+=[[bestscoresArray对象索引:i]intValue];
}
总分=新总分;
//输出 l1bestscore=15900,l2bestscore=7800,l3bestscore=81000,l4bestscore=81000,l5bestscore=0,l6bestscore=0,l7bestscore=0,l8bestscore=0,l9bestscore=0,l10bestscore=0,totalscore=185701

如您所见,totalscore输出为185701,但所有值之和为185700

有人知道为什么会这样吗

谢谢


标记您必须定义
newTotalScore
的初始值:

uint newTotalScore = 0;

否则它将是未定义的。在您的情况下,它是
1
,但它可能是任何其他值。

对此不确定,但您是否尝试将
newTotalScore
初始化为零?(请参阅关于变量初始化。)如果这没有帮助,请提供更多代码