How to create equation for updating (Packets and Sheets)

40 Views Asked by At

I have (n) Packets containing (x) sheets (1 Packet = x Sheet) where (both x and n are integers). Now I want to sale by Packet and By Sheet I created an excel file but I am very confused on how to create an equation.

for example: 4 Packets each containing (5 sheets), total Sheets = 4 * 15 = 20

Case1: I sold 1 Packet and 2 Sheets

Case2: I Sold 1 Sheet Only

Case3: I Sold 1 Packet and 1 Sheets

Balance:

4 Packets - 2 Sold = 2 Packets

(4*5=20) Sheets - 4 Sheets = 16 Sheets

Total Sold = 2 Packets (5 Sheet) + 4 Sheets = 10 + 4 = 14 Sheets It means that (Balance = 20 Sheets - 14 Sheets = 6 Sheets) Only 1 Packet and 1 Sheet remaining.

How to create an equation to update the balance after each transactions?

2

There are 2 best solutions below

0
On

Create two running variables: $p$ storing the number of unopened packets, and $s$ storing the number of left over single sheets. For each intact packet sold decrease $p$ by $1$, for each single sheet sold decrease $s$ by $1$. For each packet opened in order to bring the sheets therein to the fore decrease $p$ by $1$, and increase $s$ by the number $x$ of sheets per packet.

0
On

I got these equations and they works fine using excel and MySQL:

Sheet balance = Prev. Balance of sheet - ( (number of packet sold * number of sheet) + (number of sheet sold))

Packet Balance = Prev. Balance of Packet - (number of packets sold) - (if prev. balance of sheet % (modulus) number of sheet in packet >= number of sheets sold, 0,1)