Your optimized code will look like this:
var
RESPOSTA: CARACTERE
CONDICAO: LOGICO
inicio
CONDICAO <- VERDADEIRO
ENQUANTO CONDICAO = VERDADEIRO FACA
Escreval("==========================================")
Escreval(" Lembre-se! ")
Escreval(" Use LETRAS MAIUSCULAS ")
Escreval(" Para Responder SIM, Digite a LETRA (S) ")
Escreval("ou Digite a letra (N) para Responder Não. ")
Escreval(" Boa Sorte! ")
Escreval("==========================================")
Escreval(" ")
Escreval("Esta de acordo?: ")
Leia(RESPOSTA)
CONDICAO <- FALSO
ESCOLHA RESPOSTA
caso "s"
Escreval("!!!!!!!!!!!!!!!!!!!!!!!")
escreval("Parabéns, você acertou!")
Escreval("!!!!!!!!!!!!!!!!!!!!!!!")
caso "n"
Escreval("***************************")
Escreval(" Resposta incorreta. ")
Escreval("***************************")
Escreval(" ")
Escreval(" Vamos tentar novamente. ")
Escreval(" ")
Escreval(" ")
Escreval(" ")
CONDICAO<- VERDADEIRO
outrocaso
Escreval(" ")
Escreval(" ")
Escreval("############################################")
Escreval(" Você digitou um caracter inválido ")
Escreval("############################################")
Escreval(" ")
Escreval(" ")
CONDICAO<- VERDADEIRO
fimescolha
FIMENQUANTO
fimalgoritmo
I chose to use the command CHOICE-CASE instead of the command THEN, because it will be more complex to implement your pseudocode using this command (if-then).
However, it is worth mentioning that the optimization of pseudocode is performed in numerous ways, it may be that you find, on the Internet or with your teacher, the solution of your problem with other commands, however fully functional.
The operation of the CHOICE-CASE control is described below:
The reserved words of this instruction are escolha
, caso
and
fimescolha
, the use of outrocaso
, as with the
instruction se... entao
who can use the senao
(composite selection) or
não
(simple selection).
It is important to note that this selection instruction already has its
relational operation defined and may not be used other than
equality, which is implicit in this instruction (the symbol never appears
= in the instruction). Through it it is only possible to verify if there is equality between an integer value or desired character that is wanted
evaluate, where its veracity will result only in the execution of other
instructions available in the case that corresponds to the value equal to the
rated.
If none of the values are specified as a case of this
multiple choice instruction will be executed the available instructions
in the outrocaso
, if the same exists, or the algorithm will continue its
execution after the fimescolha
.
General Form of Syntax
escolha (<identificador>)
caso <valor_1>
primeiro bloco de instrução
caso <valor_2>
segundo bloco de instrução
caso <valor_3>
terceiro bloco de instrução
outrocaso
bloco de instrução do outro caso (valor diferente de todos anteriores)
fimescolha
// continua as instruções do algoritmo em execução
The spelling <valor_1>
, <valor_2>
and <valor_3>
correspond to
possible integer values or character that will be compared to the value
which is stored in what will be described at the beginning
of this instruction, just after the reserved word choice, being the
even in parentheses.
Thus, the relational operation of equality will be carried out without
its symbol is explicitly described in the instruction
Flowchart:
Source: Control Structures in pseudocode
Ola Kellvem, well, I don’t know if you are taking a course that requires the use of visualG, but a very good tool for those who are learning to program is Portugol Studio, has much more functionality than visualG, even allows the creation of graphic parts on the screen, You can develop your first game and everything! good studies.
– Jonathan CR