Should I use signed or unsigned variables for HP and money?

1 day ago 4

Technically, they should be unsigned, since they shouldn't be negative, however, I've seen lots of games use signed variables so I'm curious.

I know that using signed variables for HP is easier, but is that the only reason?

example if hp is unsigned: c if (enemy.dmg > player.hp) die(); player.hp -= enemy.dmg

example if hp is signed: c player.hp -= enemy.dmg if (player.hp < 0) die();

I also wonder if it has something to do with the fact that signed variables are the default type in all programming languages.

submitted by /u/Fast-Muffin7953 to r/C_Programming
[link] [comments]
Read Entire Article