Thread: more of a math problem :-/

  1. #1
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198

    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!

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    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.

  3. #3
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Help!!c problem in math
    By feelsunny in forum Tech Board
    Replies: 2
    Last Post: 10-06-2007, 03:35 AM
  3. Math Problem....
    By NANO in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-11-2002, 04:37 AM
  4. math problem
    By unixOZ in forum Linux Programming
    Replies: 4
    Last Post: 10-19-2002, 12:17 AM
  5. Little math problem
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-27-2001, 07:44 PM