Yesterday at work I came across an interesting problem that I wasn't able to figure how to structure properly. I'm relatively new to the field and was wondering if I could get some help around here. What i have here is a table like this:
|1-2| 3-5 | 6+ | ($) ________________ | | 10 - 100 | x9 x6 x4 | | | 100 - 2000| x5 x3 x2 | |______________|
Where the columns shows the base price and the row shows the quantity. The idea here is that the bigger quantity you buy, the better the price. Not only that but we would also reduce the multiplier to items with bigger base price, because otherwise the price could become too high too quickly.
The outcome I want to achieve is when given two variables - base price and quantity to find where I'm standing in the table. This means for each table entry I need two ranges.
Let me give some examples:
- Base price: 1.5$
- Quantity: 200
- Result: x5 (multiplier)
So the actual price will be 7.5$
- Base price: 10$
- Quantity: 15
- Result: x4
So the actual price will be 40$
How would you remember the data and how would you write something flexible and scalable so one is able to add and remove table rows easily?
I would evaluate the answers based on how clean the solution is. And by clean I mean easy to use and easy to implement. Currently in our system this table is made from 20 if statements so anything would be better I think!