1
I put a printf()
to track what happened and everything was normal, until I type my last value and it is assigned to the counter quantN
. The conditional even works when it is a negative value, it adds one more to the value (-5 turns -4).
#include <stdio.h>
int main(){
int i = 0, somaP = 0, quantN = 0, valores[9];
for (i = 0; i <= 9; i++){
printf("Digite o %do valor: ", i + 1);
scanf("%d", &valores[i]);
if(valores[i] < 0){
quantN++;
} else {
somaP += valores[i];
}
}
printf("Soma dos positivos: %d\n", somaP);
printf("Quantidade de negativos: %d\n", quantN);
system("pause");
}
As the array starts at position 0 ended up confusing me, now I understand how it works. And I used array because the exercise list was designed to practice it, so I didn’t even stop to ask questions. Thank you so much for answering the question and introducing me to the edited code, I will start using this pattern.
– Edi Junior