Jump to content

Calculating sales


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 post
Share on other sites

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 post
Share on other sites

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.