Visualg - Assign two variables on the same line

Asked

Viewed 1,896 times

2

I would like to know how to put 1 variable next to each other in the visualg?

Exemplo:

1.0  7.0
5.0  9.0

Since the 4 numbers are REAL variables, to simplify I want to write 1.0 below 5.0 ai the cursor goes up write 7.0 and below 9.0

var

   X1, X2, Y1, Y2, R:REAL


inicio

      Leia(X1)
      Leia(X2)
      Leia(Y1)
      Leia(Y2)
      R <- raizq((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))//FORM CALCULAR DISTANCIA
      Escreval (R:1:4)



fimalgoritmo
  • The example above is not as you would like it any more: https://www.urionlinejudge.com.br/judge/en/problems/view/1015

  • Put two ESCRIAL, one below the other, in the top line put ESCRIAL( and the respective variables of 1.0 and 7.0) in the ESCRIAL below ( the respective variables of 5.0 and 9.0) tried this already? Post your code and we’ll help you!

  • Come on, if you open the link there of the activity you will see that where the input sample is (where the user puts the values) is aligned next to each other. I want to know the command to leave my code this way.

2 answers

2


Depending on the English language manual, the read function allows the input of data, receiving the values typed by the user, assigning them to the declared variable along with the read function.

3.5.1 Internal functions

As seen in previous examples, G-Portugol offers two internal functions: "read" and "print", which allow basic use of input and output, respectively. The "read" function does not receive arguments and returns the read value of the standard input ("STDIN"), which usually means, read the data the user enters on the keyboard, followed by the "new line" character (usually associated with the "Enter" key on the keyboard). The data type returned by "read" is implicitly converted to the primitive type required in the context in which it is used.

According to the above quotation, it is understood that the 'new line' character allows the attribution of the value to the respective variable. So there is no possibility of assigning two values to two different variables IN THE SAME LINE, as we see in other languages - example: python.

Recalling the objectives of the Portuguese language:

"On the other hand, submit a beginner to the rigors of a language of programming like Pascal or the "esoterism" of C is also exaggerated. The ideal would be a simpler language, similar to "Portugol", from great popularity in academic media and present in books more used; with it, the basic principles of structured programming can be taught without the learning curve being steep."

I believe that because "Portugol" aims to be a simple language for beginners there is no possibility of Multiple assignment as in Python

Sources:

  1. Manual Portugol

  2. Manual Tool Visualg

  • Thanks for your help, pal! I believe my teacher was mistaken in passing this activity or was it just an error of interpretation on my part.

  • Check with it, if you can do in another language, which have several means of making such assignment!

1

Putting write instead of write, will keep the next command on the same line.

Ex.:

Var

A, B, C: whole

Beginning

A <- 2

B <- 3 C <- 5

Write ("A x B = ")

Typing (A*B)

Typing (C>A)

scribal (A>2)

Write (C=A+B)

Write (A+B)

On the black screen:

A x B = 6 TRUE

PHONY

TRUE 5

End of programme implementation !

Browser other questions tagged

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