1
Good afternoon guys, all right?
I have an exercise here from the Faculty of Algorithms I, follow the statement below:
Write an algorithm that asks for the age of several people (USE REPEAT). Please report the total number of people under 25 and the total number of people over 50. The program ends when age is negative (Not to be used in counting).
I’ve done the code so far, just the replay. I’m doubtful how to do the age check to inform the totals.
Code to date:
algoritmo "APS05"
var
idade:inteiro
inicio
repita
escreva("Idade: ")
leia(idade)
ate (idade<0)
fimalgoritmo
Thanks for your help.
[RESOLUTION]
repita
escreva("Idade: ")
leia(idade)
se (idade>=0) e (idade<25) entao
contMenos25 <- contMenos25 + 1
fimse
se (idade>50) entao
contMais50 <- contMais50 + 1
fimse
ate (idade<0)
escreval("Menores que 25: ", contMenos25)
escreval("Maiores que 50: ", contMais50)
A small fix in your code: don’t forget to test
se (idade >= 0 e idade < 25)
to prevent it from including negative ages in the count, as stated in the exercise.– Piovezan
But I put the
ate (idade<0)
doesn’t solve this?– tspereirarj
Does not solve because if you type negative age will enter the if before testing age < 0.
– Piovezan
Perfect now then. Thanks again for your correction and explanation.
– tspereirarj