math question.

Non-platform specific questions.

math question.

Postby tintran » Mon Feb 20, 2012 12:56 am

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?
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score

Re: math question.

Postby Game A Gogo » Mon Feb 20, 2012 12:57 am

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:
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: math question.

Postby tintran » Mon Feb 20, 2012 1:57 am

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
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score

Re: math question.

Postby Game A Gogo » Mon Feb 20, 2012 12:07 pm

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;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: math question.

Postby tintran » Tue Feb 21, 2012 3:14 am

thanks again. :)
Now i have tetris partner with multiple songs (by DST)
the only bad thing is it's 63MB instead of 6MB hehe
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest