Jump to content

how do i make my own math equation?


Monkuar

Recommended Posts

if ($user['amount'] >= 15.00){
	   $user['max_stars'] = 3;
	}

 

Ok and

 

if ($user['amount'] >= 20.00){
	   $user['max_stars'] = 4;
	}

How can I write a function that will loop through the 15,20,25,30,35, all the way up to 600$ or if the max_Stars get's up to 80?

 

I really don't want to have 80 if functions in my code :\

 

 

Link to comment
https://forums.phpfreaks.com/topic/258257-how-do-i-make-my-own-math-equation/
Share on other sites

Is it consistently X/5?

 

Hint: it's consistently X/5.

define("AMOUNT_PER_STAR", 5);
define("MAX_AMOUNT_FOR_STARS", 400); // you said 600, but $80*5=400
define("MIN_AMOUNT_FOR_STARS", 15);

if ($user["amount"] >= MIN_AMOUNT_FOR_STARS) {
    $amount = min($user["amount"], MAX_AMOUNT_FOR_STARS);
    $user["max_stars"] = floor($amount / AMOUNT_PER_STAR);
}

Normally I don't litter my code with lots of constants but for some reason I felt like it this time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.