Portugol help (ascending order)

The code below should sort the numbers entered in ascending order, but when 5,3 and 8 are entered respectively, the program displays them out of order.

Program {

funcao inicio()
{
    //variaveis
    inteiro i
    real a, b, c
    real menor=0.0, meio=0.0, maior=0.0

    leia(i)
    leia(a)
    leia(b)
    leia(c)

    se(i==1){
        se(a>b e b>c)
        maior = a
        meio = b
        menor = c
    }


         senao se(a>c e c>b){
         maior = a
         meio = c
         menor = b
    }


        senao se(b>a e a>c){
         maior = b
         meio = a
         menor = c
         }


        senao se(b>c e c>a){
         maior = b
         meio = c
         menor = a
         }


          senao se(c>a e a>b){
         maior = c
         meio = a
         menor = b
         }

     senao se(c>b e b>a){
         maior = c
         meio = b
         menor = a
         }

       escreva("\nmenor = ", menor)
       escreva("\nmeio = ", meio)
       escreva("\nmaior = ", maior) 

}

}

 0
Author: João Rosa, 2020-04-20

1 answers

You Made a little attention mistake. See this excerpt from your code:

se(i==1){
        se(a>b e b>c) //Falta a chave de abertura aqui
        maior = a
        meio = b
        menor = c
    }

You opened the keys of the conditional se(i==1){ correctly, however you did not open the keys of the next conditional structure, and as a variable b (worth 3) is not greater than the variable c ( worth 8) you never entered this conditional, mistakenly leaving the code!

To fix enter an opening key right after se(a>b e b>c).

Your Code will look like this:

    se(i==1){
            se(a>b e b>c){ //Codigo corrigido
            maior = a
            meio = b
            menor = c
        }
...
 1
Author: Luiz Augusto, 2020-04-20 20:28:33