Age Counter

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 requests the age of several people (USE REPEAT). Enter the total number of people under 25 and the total number of people over 50. The program ends when age is negative (It should not be used in counting).

I've done the code so far, just the repetition. I'm wondering how to check the ages to report the totals.

Code so far:

algoritmo "APS05"
var
   idade:inteiro

inicio

      repita
            escreva("Idade: ")
            leia(idade)
      ate (idade<0)

fimalgoritmo

Thank you in advance 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)
    
asked by anonymous 09.05.2018 / 17:00

1 answer

1

You need an integer type contadorMenosDe25Anos variable that starts at zero and increments by one each time you read an age between 0 and 25 years. Likewise a variable contadorMaisDe50Anos for ages greater than 50 years.

After the repetition, just print the value of these variables.

    
09.05.2018 / 17:06