7
I solved this exercise below and thought about putting a structure while
repeat, for the person to calculate again. But when I put’s' to return and calculate again, the exercise sums up the values of the 10 numbers I calculated earlier and sums up with the next 10 numbers. Why does this happen?
/*Ex: Faça um programa que solicite ao usuário a entrada de 10 números e
imprima como resultado a soma de todos os pares */
int vetor[10], i;
float res=0;
char op;
do {
for (i=0; i<=9; i++) {
printf("\nInforme um numero: ");
scanf("%i", &vetor[i]);
if (vetor[i] % 2 == 0) {
res = res + vetor[i];
}
}
printf("\nA soma dos pares e: %.2f", res);
printf("\nDeseja calcular novamente? ");
scanf("%s", &op);
fflush(stdin);
} while (op == 's' || op == 'S');
return(0);
Thank you guys, you’ve really helped me! ;)
– Marcielli Oliveira