# more of a math problem :-/

• 04-07-2004
linucksrox
more of a math problem :-/
I'm learning C for recreation, and I'm reading this book called C Primer Plus (third edition). Problem 7 from Chapter 7 has you prompt for input of the number of hours worked per week. Then the basic pay rate is \$10 per hour, overtime is time & 1/2 (over 40 hours), and the tax rate is .15 for the first \$300, .20 for the next \$150, and .25 for anything above. it's supposed to output the gross pay, taxes, and net pay. i can't figure out for the life of me how to do this...I'm using a bunch of complicated #define statements.
Code:

```#define PAYRATE 10.00 #define OVERTIME (1.5 * PAYRATE) #define TAX1 0.15 #define TAX2 0.20 #define TAX3 0.25 #define BREAK1 30.0 #define OT_BREAK 40.0 #define BREAK2 45.0 #define GROSS_BASE1 (PAYRATE * BREAK1) /* 300 */ #define GROSS_BASE2 (GROSS_BASE1 + ( (OT_BREAK - BREAK1) * PAYRATE) ) /* 400 */ #define GROSS_BASE3 (GROSS_BASE2 + ( (BREAK2 - OT_BREAK) * OVERTIME) ) /* 475 */ #define NET_BASE1 (GROSS_BASE1 - (GROSS_BASE1 * TAX1) ) /* 255 */ #define NET_BASE2 (NET_BASE1 - ( (GROSS_BASE2 - GROSS_BASE1) * TAX2) + (GROSS_BASE2 - GROSS_BASE1) ) /* 335 */ #define NET_BASE3 (NET_BASE2 - ( (GROSS_BASE3 - GROSS_BASE2) * TAX2) + (GROSS_BASE3 - GROSS_BASE2) )```
there's got to be an easier way to do this... thanks for any help!
• 04-07-2004
nonpuz
you could right a function like so:

calculateNET(totalwages,taxrate);

etc..then just pass the approriate tax rate 3 times, the code is not that easy to simplify as you cant really get around doing what you're doing already.....writing functions is probably the best you can do.

btw you would write a function for GROSS pay as well.
or you could do them both in one function.
• 04-08-2004
linucksrox
thanks, but I actually found a document online with some of the solutions to some of these problems, and there is a much much easier way to do it. all I needed was a few simple define statements, for tax rates, pay rate, overtime, and then a few if statements to determine gross pay, then from there determine tax from gross, and then finally deduct tax from gross and get net. i tend to think complicated instead of making things simple...and i'm tired... thanks for the help though.