Visualg G Algorithm

  1. Ask for a person's name and gender. Present at the end how many people are male and how many are female. We program terminates when the user types end in the person's name.

Can anyone help me? Every time I type end in the name, it asks for the gender of the person, I need that when I type end the closing message appears and that it does not ask for the gender.

var
   nome, sexo, fim: caractere
   qtdh, qtdm: inteiro
inicio
      qtdh <- 0
      qtdm <- 0
      enquanto nome <> "fim" faca
      
               escreval("================================================")
               escreval("Digite seu nome: ")
               leia(nome)

               escreval("================================================")
               escreval("Digite seu sexo (F ou M):")
               leia(sexo)
                  
               se (sexo="F") entao
                  qtdm <- qtdm + 1
               senao
                    se (sexo="M") entao
                       qtdh <- qtdh + 1
                    fimse
               fimse
      fimenquanto
      escreval("Foram digitados", qtdh, " do sexo masculino e", qtdm, " do sexo feminino")

fimalgoritmo
Author: grazisousa0101, 2020-10-14

1 answers

It will be necessary to make a condition preventing it from executing the rest of the code block, for this it will be necessary to define the variable nome of type literal, since it is a string, and then you check if the value of it is different from 'end' before proceeding.

//Define o valor de nome
se nome <> "fim" entao
    //Define o sexo
fimse

Applying, would be:

var
    nome: literal
    sexo, fim: caractere
    qtdh, qtdm: inteiro
inicio
    qtdh <- 0
    qtdm <- 0
    enquanto nome <> "fim" faca
        escreval("================================================")
        escreval("Digite seu nome: ")
        leia(nome)

        se nome <> "fim" entao
            escreval("================================================")
            escreval("Digite seu sexo (F ou M):")
            leia(sexo)
                  
            se (sexo="F") entao
                qtdm <- qtdm + 1
            senao
                se (sexo="M") entao
                    qtdh <- qtdh + 1
                fimse
            fimse
        fimse
    fimenquanto

    escreval("Foram digitados", qtdh, " do sexo masculino e", qtdm, " do sexo feminino")

fimalgoritmo
 4
Author: Vitor Subhi, 2020-10-14 13:57:56