Is there any way to round a negative value to zero in VisuAlg?

2

I would like to always display Vida: 0 in the last block, even if the value is negative, without doing this "Gambiarra" that I made just below.

Is there a function that rounds vidaInimigo , without having to create an additional condition: Se(vidaInimigo <= 0) entao EscrevaL("Vida: 0") ?

Becausetheenemyhad4ofLife,received%with%ofDamage,andgot39oflife.

IwantedLifetobedisplayedequalto-35,not0.

Iimaginethereissomefunctionthatroundsup.

Followthealgorithmcode:

algoritmo"RPG"
var
   danoCausado, vidaInimigo, baseDanoPlayer: Inteiro
inicio
   baseDanoPlayer <- 50
   vidaInimigo <- 100
   EscrevaL("Vida: ", vidaInimigo)
   Repita
       danoCausado <- randi(baseDanoPlayer)
       vidaInimigo <- vidaInimigo - danoCausado
       EscrevaL(" >>> Dano causado: ", danoCausado)
       Se(vidaInimigo <= 0) entao
           EscrevaL("Vida: 0")
           senao
           EscrevaL("Vida: ", vidaInimigo)
       FimSe
   Ate(vidaInimigo <= 0)
   Se (vidaInimigo <= 0) entao
       EscrevaL("Inimigo abatido!")
   FimSe
fimalgoritmo

    
asked by anonymous 06.06.2018 / 13:07

1 answer

1

How about replacing this:

Se(vidaInimigo <= 0) entao
    EscrevaL("Vida: 0")
    senao
    EscrevaL("Vida: ", vidaInimigo)
FimSe

So:

Se(vidaInimigo < 0) entao
    vidaInimigo <- 0
FimSe
EscrevaL("Vida: ", vidaInimigo)
    
06.06.2018 / 14:35