tleylan@pegasus.com (Tom Leylan) (12/29/90)
This doesn't have to be done in C necessarily but I know this is where all the smart programmers hang out... I have a number of involved calculations to make (sets of them for various conditions) and I wondered if there is a way to approach this besides dozens of SWITCH statements and IF...ELSE and all the other conditionals ? Particularly useful would be the ability to have it "read" like one would describe the problem in English but I don't expect that. For instance : cost is 3% of total unless total is greater than $1000 then cost is 3% of the first $1000 and 2% of the balance. A minimum charge of $20 applies. Know what I mean ? Is there a math library or a programming discipline that I could apply here ? Many thanks. tom j
brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (12/31/90)
In article <1990Dec29.073901.1810@pegasus.com> tleylan@pegasus.com (Tom Leylan) writes: > This doesn't have to be done in C necessarily but I know this is where > all the smart programmers hang out... Then your article is not appropriate for this group. [ how to make programs ``read'' like English ] > For instance : cost is 3% of total unless total is greater than $1000 then > cost is 3% of the first $1000 and 2% of the balance. A minimum charge of > $20 applies. cost = 0.03 * total; if (total > 1000.00) cost = 0.03 * 1000.00 + 0.02 * (total - 1000.00); if (cost < 20.00) cost = 20.00; ---Dan
tleylan@pegasus.com (Tom Leylan) (01/02/91)
In article <18444:Dec3104:13:5090@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: > >cost = 0.03 * total; >if (total > 1000.00) > cost = 0.03 * 1000.00 + 0.02 * (total - 1000.00); >if (cost < 20.00) > cost = 20.00; > Dan, Thanks for "solution" I obviously didn't phrase my query correctly as it wasn't _that_ particular problem I was interested in solving it was the problem of solving whatever business formula was required. Some start with a base commission depending upon monthly sales with minimums and maximums and 10 companies can calculate it 10 different ways. I'm trying to avoid being a "formula maintainer" for the rest of my career. A few people have suggested that I write my own little math formula processor and that sound like the solution... a sort of SQL for math problems. I also accidentally (I stand behind the 5th amendment to the Constitution) posted my message as a follow-up to someone elses thread and while I'm sorry I did it it seems irreversible at this point. tom