Visualg G Algorithm

Asked

Viewed 66 times

3

  1. Ask for a person’s name and sex. Present at the end how many people are male and how many are female. The program terminates when user type ORDER in person name.

Can someone help me? Every time I type order in the name, it asks for the sex of the person, I need that when typing ending to appear the closing message and that do not ask the sex.

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

1 answer

4


You will need to make a condition preventing you to execute the rest of the code block, for that you will need to set the variable nome of the kind 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
  • Aah worked out, thank you very much, only missed the """"#no > if name <> end then

  • Corrected. If this answer solved your problem and there is no doubt left, mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.