c# - Dividing with rest 0 -
i have question. have 2 numbers example:
81 / 9 or 25 / 5 or 12 / 6 , on..... these 2 numbers appear randomly.
public simplespritesequence[] leftnumbers; public simplespritesequence rightnumbers; public simplespritesequence numberresul; randomizer numbersequence = new randomizer(1, 9); public void getnumbers() { if (!numbersequence.randomrule.hasnumbersleft()) { numbersequence.randomrule.reset(); } int firstnumberindex = numbersequence.getrandom(); leftnumbers[0].setcurrentspriteindex(firstnumberindex); if (!numbersequence.randomrule.hasnumbersleft()) { numbersequence.randomrule.reset(); } int secondnumberindex = numbersequence.getrandom(); leftnumbers[1].setcurrentspriteindex(secondnumberindex); if (!numbersequence.randomrule.hasnumbersleft()) { numbersequence.randomrule.reset(); } int rightnumberindex = numbersequence.getrandom(); rightnumbers.setcurrentspriteindex(rightnumberindex); int findex = 10 * (int)leftnumbers[0].currentspriteindex; int sindex = (int)leftnumbers[1].currentspriteindex; int number = findex + sindex; int lindex = (int)rightnumbers.currentspriteindex; result = number / lindex; debug.log(number + ":" + lindex + "=" + (math.truncate(result))); while(math.truncate(result) >= 10) { if (!numbersequence.randomrule.hasnumbersleft()) { numbersequence.randomrule.reset(); } firstnumberindex = numbersequence.getrandom(); leftnumbers[0].setcurrentspriteindex(firstnumberindex); if (!numbersequence.randomrule.hasnumbersleft()) { numbersequence.randomrule.reset(); } secondnumberindex = numbersequence.getrandom(); leftnumbers[1].setcurrentspriteindex(secondnumberindex); if (!numbersequence.randomrule.hasnumbersleft()) { numbersequence.randomrule.reset(); } rightnumberindex = numbersequence.getrandom(); rightnumbers.setcurrentspriteindex(rightnumberindex); findex = 10 * (int)leftnumbers[0].currentspriteindex; sindex = (int)leftnumbers[1].currentspriteindex; number = findex + sindex; lindex = (int)rightnumbers.currentspriteindex; result = number / lindex; }}
with code operations these: 13:6 = 2 or 24:7 = 3 , on. how operations rest 0? example: 81 : 9 or 24 : 8 or 12 : 6 , on. how put condition?
you should use modulo operator uses %
operator-symbol. returns remainder of division, instead of result.
12 % 6 = 0 21 % 3 = 0 21 % 6 = 3
it's nice identify odd , numbers.
Comments
Post a Comment