Unknown98 Posted May 28, 2013 Share Posted May 28, 2013 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 . 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. Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 28, 2013 Share Posted May 28, 2013 Put an if statement in to make sure the inventory is at, or above 0 for the hour. Quote Link to comment Share on other sites More sharing options...
Solution Unknown98 Posted May 28, 2013 Author Solution Share Posted May 28, 2013 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). Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 29, 2013 Share Posted May 29, 2013 We all have those. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.