I'm learning c++ by myself and I'm currently having trouble making the sum between array values (if >0 else <0).
This is what I've been doing (bilIniziale is my array):
for (int i=0;i<10;i++){
int sum = 0;
if(bilIniziale[i] > 0) {
sum+=bilIniziale[i];
}else{
sum+=bilIniziale[i];
}
}
I also tried with sum = sum + bilIniziale[i];
but no difference.
In the terminal at the moment its only shows the element >0 or <0 but without summing between them; how can I do it?
sumis a local variable in your loop, so it is reset to zero every time and not visible outside the loop.