0
Could I show you Life: 0 in the Visualg console output?
I tried to put Ate(life = 0) but gives infinite loop.
If anyone can help me, I’d appreciate it.
The version of my Visualg is the 2.0
algoritmo "RPG"
var
damage, life: Inteiro
inicio
life <- 100
EscrevaL("Vida: ", life)
Repita
EscrevaL(" >>> Dano causado: ", damage)
EscrevaL("Vida: ", life)
damage <- randi(life)
life <- life - damage
Ate(life = 1)
Se (life = 1) entao
EscrevaL("Inimigo abatido!")
FimSe
fimalgoritmo
Try with
life <= 0
. Whydamage
receivesrandi(life)
?– Woss
Ate(life <= 0)
looped in as well.damage
receivesrandi(life)
in order to generate a random number from the100
whylife <- 100
. Therandi
is a randomization function.– user115381
Is there an example of the output when it loops? By the way,
randi(life)
can returnlife
or is 0 tolife-1
?– Woss
Replaces
damage <- randi(life)
fordamage <- randi(80)
. Now it’s stopped looping even withAte(life <= 0)
. Looks like it’s working now. Click here to see the image– user115381
Yeah, so you can use
life = 0
and putrandi(life+1)
– Woss
Only as an aside, if you are in a language where the reserved words are in Portuguese, why not use variable names also in Portuguese ?
– Isac
randi(life+1)
also worked, I think it solves better than my gambiarra to putrandi(80)
. Thank you.– user115381
That’s why life was coming to
0
and therandi
was trying to randomize the0
, so I was looping in.– user115381
Truth @Isac, I could have followed the Portuguese, but it was just for testing, thanks for helping me.
– user115381