Program error in VisualG
I'm having problems with this program, because when I put to work and type a value greater than 18, a message appears saying that it is missing a FIMSE
and that there is a FIMENQUANTO
without a corresponding ENQUANTO
.This is the purpose of the program:to make a program that requests fifteen ages and check the age range according to the table below. Present all input and output data.
inicio
n <- 0
i <- 0
escreval ("Digite 15 idades: ")
enquanto (i < 15) faca
leia (n)
i <- i + 1
se (n < 18) entao
escreval ("Sua idade corresponde a classificação: criança")
senao se (n < 30) entao
escreval ("Sua idade corresponde a classificação: jovem")
senao se (n < 60) entao
escreval ("Sua idade corresponde a classificação: adulto")
senao
escreval ("Sua idade corresponde a classificação: idoso")
fimse
fimenquanto
fimalgoritmo
2 answers
The problem is in the mode in which you are using the condition structure:
se (condicao) entao
<comandos>
senao
<comandos>
fimse
You always need to close the structure when you start it, so to perform a sequence of checks you need to be careful with the identity of your portugol. For this example of your question to work, you would have to do like this:
Algoritmo "teste"
Var
// Seção de Declarações das variáveis
n,i,qtd: inteiro
Inicio
// Seção de Comandos, procedimento, funções, operadores, etc...
i <- 0
escreval("Digite quantas idades vc quer classificar: ")
leia(qtd)
enquanto (i < qtd) faca
escreval("Digite uma idade: ")
leia(n)
se (n < 18) entao
escreval ("Sua idade corresponde a classificação: criança")
senao
se (n < 30) entao
escreval ("Sua idade corresponde a classificação: jovem")
senao
se(n < 60) entao
escreval ("Sua idade corresponde a classificação: adulto")
senao
escreval ("Sua idade corresponde a classificação: idoso")
fimse
fimse
fimse
i <- i + 1
fimenquanto
Fimalgoritmo
See that I made a small change at the beginning of it where you tell the amount of ages you want to check the rating.
Tries like this:
inicio
n <- 0
i <- 0
escreval ("Digite 15 idades: ")
para i de 1 ate 15 faca
leia (n)
se (n < 18) entao
escreval ("Sua idade corresponde a classificação: criança")
fimse
se (n < 30 e n>18) entao
escreval ("Sua idade corresponde a classificação: jovem")
fimse
se (n < 60 e n>30) entao
escreval ("Sua idade corresponde a classificação: adulto")
fimse
se(n>60) entao
escreval ("Sua idade corresponde a classificação: idoso")
fimse
fimenquanto
fimalgoritmo
Was missing other comparisons in the if's. (notice that you did n