Thread: tax program

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    tax program

    i am very new to C, and programming all together, so i've been going through Practical C Programming (any online tutorials or other books that you could suggest would be appreciated), and i ran into and exercise i was having trouble with. it asks you to put an 8% sales tax on to a dollar amount entered and round it to the nearest penny. the part im having trouble with is how to cut the number off at the penny. i was thinking about a couple different ways of doing it using a loop to test for the decimal and then cutting the loop off after two more times, but i kept running into problems because after the sales tax is added i stored it in a interger variable, and i dont know how i could test that. any advice would be a great help
    -sam

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You can round to the nearest penny multiplying it by 100. Add 0.5 to it, floor it, then divide back down by 100.

    Edit: sorry I dident notice you were using integers.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    10
    Why don't you just store the value after tax is applied into a float?

    -Dustin
    C tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Tax calculator program
    By Mshock in forum C++ Programming
    Replies: 1
    Last Post: 06-28-2006, 03:28 PM
  2. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  3. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM