0

Hi,

Why is it that when I remove(commented out) the inner j for loop and all it's contents, the cmd prints out my desired output. However, replacing back the inner for loop, it gives an incorrect output -> my counter values are wrong when printed. Can anyone spot what I have missed out? I need that inner for loop to be there in order to calculate my centroids 5 different times based on the varying counts that I'm incrementing in my i for loop. Below is my code:

```
for(int k=0;k<5;k++){
e_count=0, b_count=0, n_count=0, r_count=0;
for (int i=0;i<RLEN;i++){
if(rri_val[i][2309]!=k && rri_val[i][2308]==EWS)
e_count++;
if(rri_val[i][2309]!=k && rri_val[i][2308]==BL)
b_count++;
if(rri_val[i][2309]!=k && rri_val[i][2308]==NB)
n_count++;
if(rri_val[i][2309]!=k && rri_val[i][2308]==RMS)
r_count++;
//This is the for loop I'm talking about!!!
for(int j=0;j<CLEN;j++){
if(rri_val[i][2309]!=k){ //calculates the training samples' centroids
if(rri_val[i][2308]==EWS){
temp+=rri_val[i][j]; //EWS Centroid
}
centroid[EWS][j]=temp/e_count;
temp=0;
if(rri_val[i][2308]==BL){
temp+=rri_val[i][j]; //BL Centroid
}
centroid[BL][j]=temp/b_count;
temp=0;
if(rri_val[i][2308]==NB){ //NB Centroid
temp+=rri_val[i][j];
}
centroid[NB][j]=temp/n_count;
temp=0;
if(rri_val[i][2308]==RMS){
temp+=rri_val[i][j]; //RMS Centroid
}
centroid[RMS][j]=temp/r_count;
temp=0;
}
else if(rri_val[i][2309]==k){
t[i][j]=rri_val[i][j]; //stores test sample
}
} //ends inner most for loop
} //ends i for loop
cout<<e_count<<" "<<b_count<<" "<<n_count<<" "<<r_count<<endl;
}//ends k for loop
```

Thanks.