Visual G: what does the ': 'character mean and how does it influence the results or not?
I'm learning to use the G visual by this stuff here: http://eletrica.ufpr.br / ~rogerio/visualg/Help/linguagem2.htm
In this particular code I have a very small question, which contains no answers neither in the material nor in google.
algoritmo "exemplo"
var x: real
y: inteiro
a: caractere
l: logico
inicio
x <- 2.5
y <- 6
a <- "teste"
l <- VERDADEIRO
escreval ("x", x:4:1, y+3:4) // Escreve: x 2.5 9
escreval (a, "ok") // Escreve: testeok (e depois pula linha)
escreval (a, " ok") // Escreve: teste ok (e depois pula linha)
escreval (a + " ok") // Escreve: teste ok (e depois pula linha)
escreva (l) // Escreve: VERDADEIRO
fimalgoritmo
What I didn't understand is how x(2.5):4: 1 equals 2.5 ? Type, or character ' : 'has no value at all and why the numbers 4 and 1?
Did not understand what this character':' means and how it influences or not on the results.
1 answers
By the documentation, the visualg is following the Pascal model of writing. Anything, see the documentation in Pascal
As for the code: x:4:1
means four characters at most in the output, one after the decimal place; if the number does not fill the four characters, it puts blanks. In the linked Freepascal documentation, the output would be 2.5
, with a space to the left of the printed number.
To see the effect, try printing 5.3:7:2
, you must print 5.30
. Three spaces before the number, two decimal places. Another interesting test is to print 5.29:3:1
, where the output (if rounded) is 5.3
; three characters, a single decimal place.