Display 2 data in visualg with repeat structure

Asked

Viewed 85 times

0

I’m trying to display 2 names with, Stop and do, if I put the scribe inside the loop it will read and write there gets messy, as I would read the 2 later write?

Algoritmo "semnome"
Var
i,:inteiro
nome:caractere


Inicio
para i de 1 ate 2 faca
escreval("Digite o nome: ")
leia(nome)

fimpara
escreval("Nome: ",cont)

Fimalgoritmo

1 answer

0

I don’t know much about Visualg, but let’s go with logic:

For you to read and store various values it is necessary that you have variables to dedicate memory space to this. Instead of creating multiple variables (name1,Nome2,name3) you can create a vector:

vet: nomes [1..10] de caractere //1..10 é o inicio e fim do seu vetor.

So just go adding names in this "list" of names through a PARA and then give another repeat loop to traverse this array.

Algoritmo "semnome" 
Var i,:inteiro 
vet: nomes [1..2] de caractere //1..2 é o inicio e fim do seu vetor.

Inicio 
  para i de 1 ate 2 faca 
    escreval("Digite o nome: ") 
    leia(nomes[i])
  fimpara 

//Inicio de outro PARA para escrever os nomes.
  para i de 1 ate 2 faca 
    escreval("Nome: ",nomes[i])
  fimpara 

As I said, my knowledge of visualg is not there those things but I believe it helps :D

Browser other questions tagged

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