1
I’m trying to make an algorithm here with this statement:
Given an integer n, n>0, and a sequence with n integers, determine the sum of the positive integers of the sequence. For example, for sequence 6 -2 7 0 -5 2 4 your program should write the number 19.
The problem is time to add up. That’s the code I made:
var numero;
var soma;
for (var i = 0; i < 7 ; ) {
numero=prompt("Entre com o numero: ");
parseInt(numero);
while (numero > 0) {
soma = soma + numero;
numero = 0;
}
i++;
}
document.write("A soma dos positivos é: "+soma);
What happens is that the numbers don’t add up and I have no idea how to make them add up.
Thanks, you’ve helped a lot.
– Rafael Fernandes