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

0

I'm now beginning to study programming and on account of that I'm using VisualG to be easier to pick up on programming logic. It turns out that I'm trying to develop an algorithm that guesses the age of the person. It's pretty 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 number of the variable S before it was modified by + 5 . I can not explain it right, but I'll give you an example:

Let's suppose that the person chooses the number 5. The program will do x2 that will give 10 and soon after that I wanted that in the last line of code that 10 appeared in the variable "N" and then at the end of the command write appear or "15". Something like "The sum between 10 and 5, is 15".

How do I do this?

Thank you all for responding.

    
asked by anonymous 10.11.2016 / 19:10

2 answers

0

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

As you did, and this is correct, store the value in% with% of multiplication:%% of%

Now let's use the value that is in S to perform the sum of S <- N1 * 2 : S

And then display the message to the user:
+5

The complete code remaining:

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
    
10.11.2016 / 19:44
1

I've never used visualg, so you have to modify it the way it does:)

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

It would be something like:

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

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

or

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

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

soma: s (m+5)

I now printed the modified variable on the screen:)

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

Finally, I hope I have helped.

    
10.11.2016 / 19:47