Jump to content

Calculating sales


Unknown98
Go to solution Solved by Unknown98,

Recommended Posts

What I have is a formula to calculate sales for a company, for an online game where users create and run their own businesses. So depending on # of employees, wages, and your product price, among other things, it calculates the amount of sales you will generate in 1 hour. The problem that I've run into is, how do I limit the sales based on the current inventory? For example, there will be times when the formula calculates that they should sell 5 products this hour. However there is only 4 products in their inventory. So, their sales would be limited to 4 instead of 5.

 

$units_in_stock is my variable for inventory, and $sales is the variable for their sales.

 

I know what I need to do, I just can't think of how to do it  :shrug:. I thought of doing an if statement, but I couldn't think of how to make it so that it would sell the maximum possible products based on the amount they have available. 

Link to comment
Share on other sites

  • Solution

I just figured it out... must have brain problems from coding all afternoon  ::)
 
 

if($units_in_stock < $sales){
$sales = floor($units_in_stock);
}

That checks if their inventory is less than sales, and if it is, changes the sales number to their inventory number, rounding down (because you can't sell a partial product).

 

 

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.