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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.