vendredi 6 décembre 2019

Why this IF statement doesn't print inside a loop

Could you please help me out to understand why the If statement is not executing. Thank you for your time.

    void allPerfects (int a, int b){

     int minVal = minN(a, b);
     int maxVal = maxN(a, b);
     int sum =0;
     vector<int> v;

     while (minVal < maxVal){
        v.push_back(minVal);
        minVal++;
     }
     for (int i = 0; i < v.size() ;i++){        
         for (int j = 0; j < i; j++){
            sum += v[j];
         }
         if (sum == v[i]){
            printInt(v[i], false); printStr(" is a perfect number!", true);
         }
     }
    }

Aucun commentaire:

Enregistrer un commentaire