2010-11-19 15 views
0

Bir dizide tutulan değerleri ekliyorum ama toplam, gerçekte olması gereken +1.iPhone matematiği tam olarak eklenemiyor

//update totalscore 
    uint newTotalScore; 

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

    } 


    totalscore = newTotalScore; 

// çıkış l1bestscore = 15900, l2bestscore = 7800, l3bestscore = 81000, l4bestscore = 81000, l5bestscore = 0, l6bestscore = 0, l7bestscore = 0, l8bestscore = 0, l9bestscore = 0, l10bestscore = 0 , totalscore Eğer totalscore çıkış 185.701 olduğunu görebileceğiniz gibi 185701

= ancak tüm değerlerin toplamı 185700.

herkes bu oluşmasını neden herhangi bir fikir olurdu mı?

sayesinde

Mark

cevap

9

Sen newTotalScore 'ın başlangıç ​​değeri tanımlamak gerekir:

uint newTotalScore = 0; 

Aksi takdirde tanımsız olacaktır. Durumunuzda 1 idi, ancak başka bir değer olabilirdi.

2

Bu konuda emin değilsiniz, ancak newTotalScore'u sıfırlamaya çalıştınız mı? (Değişken başlatma hakkında this question'a bakın.) Bu yardımcı olmazsa bize daha fazla kod verin.