-
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
-
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.
-
Why don't you just store the value after tax is applied into a float?
-Dustin
C tutorials