UndeadDragon
Super Moderator
- Reaction score
- 447
I have turned to the members of here to try and figure out what the problem is with this, because I give up.
Why can my program not do ((80/100)*100)*5.
Simple enough formula. It works out the percentage of health that an enemy has left and then *5 to add it to the health bar. Why does this return 0?!
No matter what I try I cannot make it return anything but 0. It will be using the variables, so it will be in this form:
int healthBarWidth = ((enemyHealth / maxEnemyHealth) * 100) * 5;
However, it also returns 0 when I use absolute values, 80 and 100 for example. You can try it in a calculator, it returns 400.
Here's my code if anyone can shed some light on it:
The message boxes that appear are: "80 100", "0" and "((80/100)*100)*5"
Thanks.
Why can my program not do ((80/100)*100)*5.
Simple enough formula. It works out the percentage of health that an enemy has left and then *5 to add it to the health bar. Why does this return 0?!
No matter what I try I cannot make it return anything but 0. It will be using the variables, so it will be in this form:
int healthBarWidth = ((enemyHealth / maxEnemyHealth) * 100) * 5;
However, it also returns 0 when I use absolute values, 80 and 100 for example. You can try it in a calculator, it returns 400.
Here's my code if anyone can shed some light on it:
Code:
Ability ability = new Ability(abilityPressed);
int damage = calculateDamage(abilityPressed);
enemyHealth -= damage;
MessageBox.Show(maxEnemyHealth.ToString() + " " + enemyHealth.ToString());
int healthBarWidth = ((enemyHealth / maxEnemyHealth) * 100) * 5;
MessageBox.Show(healthBarWidth.ToString());
healthBar.Width = healthBarWidth;
MessageBox.Show("(("+enemyHealth.ToString() + "/" + maxEnemyHealth.ToString() + ") * 100) * 5");
The message boxes that appear are: "80 100", "0" and "((80/100)*100)*5"
Thanks.