- Home /
(C#) Figure out when a number (int) reaches every tens
Hello all, I am sorry for my poorly formulated topic.
Anyhow, I am trying to figure out how to "calculate" when a number hits 10, 20, 30, 40 etc. And it must be a simpler and more clever way to do this instead of saying:
If (ComboMultiplier == 10){
DoSomething1();
}
If (ComboMultiplier == 20){
DoSomething2();
}
If (ComboMultiplier == 30){
DoSomething3();
}
The ComboMultiplier adds a number (combomultiplier += 1) when you do a successful attack on a enemy. And I want the combo number flash on the screen every 10th successful attacks in a row. (I have a working code for the combomultiplier, so don't you worry about that :) )
In advance, thanks!
Simon
A bit late but how did you do the flash of the combo-number? I'm still looking for a good way to do it ^^
Answer by Tanshaydar · Nov 11, 2014 at 03:45 PM
Instead of doing it, you can do it this way:
if(ComboMultiplier % 10 == 0){
// This means that ComboMultiplier is multiplier of 10 (10, 60, 250, 125360)...
}
if you'd like to know how many 10s there are, it's this way:
int multiplier = ComboMultiplier / 10;
// This will give you how many 10s there are ( 10 -> 1, 60 -> 6, 250 -> 25, 125360 -> 12536)
So, you can do this:
if (ComboMultiplier % 10 == 0){
switch( ComboMultiplier / 10) {
case 1:
DoSomething1();
break;
case 2:
DoSomething2();
break;
case 3:
DoSomething3();
break;
}
}
Hope this helps :)
Wow this seems like what I was looking for, will test it! Thanks for the quick reply sir!