Page 1 of 1
math question.
Posted:
Mon Feb 20, 2012 12:56 am
by tintran
if ((score >= 1) && (score <= 5) songnumber = 1;
if ((score >= 6) && (score <= 10) songnumber = 2;
if ((score >= 11) && (score <= 15) songnumber = 3;
and so on...
is there a way to do it without using if? like a math equation maybe?
Re: math question.
Posted:
Mon Feb 20, 2012 12:57 am
by Game A Gogo
songnumber=(int)(score/5)+1;
should work
EDIT:
songnumber=(score)?(int)(score/5)+1:0;
because if score is 0, then songnumber should be zero according to your code O:
Re: math question.
Posted:
Mon Feb 20, 2012 1:57 am
by tintran
thanks Gogo, but if score is 5 songnumber will be int(5/5)+1 which is 2 i want it to be 1.
i know it's probably something really simple, i just can't come up with it right now.
Edit:
I think
songnumber = (int)((score-1)/5) + 1
Re: math question.
Posted:
Mon Feb 20, 2012 12:07 pm
by Game A Gogo
yes, that will do! Sorry I didn't came up with the right formula! But yours should do the job perfectly, but it still needs an in-line if statement for it to equal 0 when the score is 0!
songnumber=(score)?(int)((score-1)/5)+1:0;
Re: math question.
Posted:
Tue Feb 21, 2012 3:14 am
by tintran
thanks again.
Now i have tetris partner with multiple songs (by DST)
the only bad thing is it's 63MB instead of 6MB hehe