In Portugol, the types of data which we use to learn programming logic are of the primitive type(making an analogy with other programming languages), that is, they do not represent a Class and, consequently, they do not have a scope with attributes and methods that are very useful. So, to solve your problem, I used the Library Texto
to be able to use some functions and reach your expected result. Remember that in the code I implemented, you can enter as many values as you find necessary, separating them by space(seen in your comments).
Follows the code:
programa
{ //Considerar a biblioteca Texto como o atributo *tx*
inclua biblioteca Texto --> tx
funcao inicio()
{
cadeia respostaCompleta
inteiro tamanho
cadeia numero = ""
escreva("Digite uma sequência de números, separando-os por espaço: ")
leia(respostaCompleta)
respostaCompleta = respostaCompleta + " "
inteiro tamanhoResposta = tx.numero_caracteres(respostaCompleta)
//Loop que varre os caracteres armazenados na resposta.
para (inteiro contador = 0; contador < tamanhoResposta ; contador ++)
{
//Concatena o número atual com o seguinte(para os números com mais de um dígito, ex:55, 130...), caso não tenha espaço separador.
numero = numero + tx.obter_caracter(respostaCompleta, contador)
se
(
//Separa os números digitados por espaço, para exibí-los.
tx.obter_caracter(respostaCompleta, contador) == ' '
)
{
escreva("Seu número foi: ", numero, "\n")
numero = ""
}
}
}
}
The idea was to use the function numero_caracteres
of the imported library to be able to scan the response characters and check with obter_caracter
if there is Espace number separators.
Note: Remember that to capture your answer, I used the datatype cadeia
, once the guy inteiro
as the name already says, it only accepts integer values and, space-separated numbers are not considered integers for the Portugol Studio.
For that answer, I used the version v2.7.2 of Portugol Studio.
Have you seen the recommended examples on the official website? As you would in any language, you can only receive input with a tab (e.g.:
5 2
), separatorespaço
and then use a loop to retrieve the values. Obs: I didn’t use/used Portugol Studio, I just based their documentation videos– Tuxpilgrim
Portugol is the same as for pseudo-code with read command()?
– Maurício Z.B
I don’t understand the question
– Lucas Emanuel
I’m sorry I can not arrive in time for your competition, but follows the detailed answer of how to solve this problem using the Portugol Studio.
– RXSD