How to make the variable appear on the screen before it is modified?

Asked

Viewed 169 times

0

I am starting now to study programming and because of that I am using Visualg to be easier to get the programming logic. It turns out I’m trying to develop an algorithm that can guess a person’s age. It’s very simple, but I’m not getting any details on this algorithm.

algoritmo "valores"
var
N1,S,S2: inteiro
inicio
Escreva ("Olá, vou adivinhar a sua idade. Pense em um numero de 1 a 10: ")
Leia (N1)
S <- N1 * 2
Escreva ("OK, multipliquei esse numero por 2 e a soma é ",S,". Agora vou adicionar 5")
S <- N1 + 5
Escreva ("A soma entre"
fimalgoritmo

This is incomplete as you can see. I wanted to put in the last line of code the variable number S before it is modified by + 5. I can’t explain it properly, but I’ll give you an example:

Let’s assume that the person chooses the number 5. The program will make x2 that will give 10 and soon after I wanted that in the last line of code appear this 10 in the variable "N" and then at the end of the command write appear the "15". It would appear something like "The sum between 10 and 5, is 15".

How do I do it?

Thank you to all who answer me.

2 answers

1

I never used the visualg, so you have to modify the way there :)

If I understand, you can assign these values in different variables or ask to print the value before you add!

It would be something like:

valor pensando: n1
multiplica: m (n1*2)
soma: s (m+5)

When displaying: "The value thought is 'n1', multiplied is’m' and the total is’s'..

or

valor pensando: n1
multiplica: s (n1*2)

shows on screen the variable s, before being modified, now you modify:

soma: s (m+5)

I have now printed the modified variable on the screen :)

I hope that I have understood well and that my explanation has become good, rs...

Anyway, I hope I’ve helped.

  • Thank you so much! I’ll try to do that

0


Arthur, you have 3 variables defined S,S2 and N1, right? So let’s use the S and S2.

As done, and this correct, keep the value in S of multiplication:
S <- N1 * 2

Now let’s use the value that is in S to realise the sum of +5:
S2 <- S + 2

And then display to the user the message:
Escreva ("A soma entre ",S," e 5, é ",S2)

The complete code getting:

algoritmo "valores"
var
N1,S,S2: inteiro
inicio
Escreva ("Olá, vou adivinhar a sua idade. Pense em um numero de 1 a 10: ")
Leia (N1)
S <- N1 * 2
Escreval ("OK, multipliquei esse numero por 2 e a soma é ",S,". Agora vou adicionar 5")
S2 <- S + 5
Escreva ("A soma entre ",S," e 5, é ",S2)
fimalgoritmo
  • Thank you very much for the explanation

  • Managed to solve problem, if yes mark as solved the answer that helped you most :)

  • How do I get the best answer? I recently started on this forum

  • In the desired question to mark as the best answer, on the left side has a symbol of Right, click on it. If you cannot access the [tour] for more details.

  • In case you didn’t notice

  • It worked, yes, thank you Arthur

Show 1 more comment

Browser other questions tagged

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