LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

help with subtraction

Root / Programming Questions / [.]

PliskenCreated:
So I was making this RPG pokemon type fighting example (I unfortunately don't have it anymore, I think I lost it during a transfer) But I remember having a problem with subtraction. If the amount being subtracted was a single digit number, it would do just fine. but If it had more then one digit like 10 or 13, it would return with a decimal. So how do I prevent this from happening? (the calculations were for health BTW)

I don't understand how that happens... What code are you using? Because there shouldn't be much of a problem if you're doing something like this:
ATK = whatever
HP = HP - ATK

I don't understand how that happens... What code are you using? Because there shouldn't be much of a problem if you're doing something like this:
ATK = whatever
HP = HP - ATK
It was so long ago I can't even remember how it was coded. I was thinking maybe I was making a simple mistake that might be common. I'm pretty sure it was similar to what you posted though. I eventually just made the max health 9 because of this problem but it's been bugging me ever since.

Well, I am not sure what it could have been but if it happens again or you want to troubleshoot that section of code you could try
HP = ROUND(HP-ATK)
This would round to the nearest whole number.

Well, I am not sure what it could have been but if it happens again or you want to troubleshoot that section of code you could try
HP = ROUND(HP-ATK)
This would round to the nearest whole number.
Ok thanks. That should help