CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 17

Threaded View

  1. #1
    Join Date
    Apr 2013
    Posts
    12

    Calculation Problems

    I am writing a program for my beginning c++ class. It is supposed to create an invoice in the console window. so far, everything is working perfectly, except for one thing.

    My invoice comes out looking like this:

    696.60 - 27 Adult Meals at $25.80 each.
    + 46.44 - 3 Child Meals at $15.48 each.
    --------
    743.04 - Total Cost of All Meals (Add the above numbers together)
    + 52.01 - Weekend Surcharge (743.04 x .07)
    +143.11 - Tax/Tip ((743.04 + 52.01) x .18)
    --------
    938.16 - Total Party Cost
    - 57.50 - Deposit Received
    --------
    880.66 - Balance Due
    - 32.84 - 3.5% Prompt Payment Discount (938.16 x .035)
    --------
    847.83 - Balance Due (If Paid Within Ten Days)

    The problem is that if I add these numbers on a calculator, I get as result of $847.82, not $847.83. I checked them individually and they are all being rounded properly. If I add them up using the entire decimal value of the calculations, rather than the truncated value, I get $847.83.

    So, the question is as follows:

    In C++, how do I do each calculation, round the answer to 2 decimal places, then use only the rounded number in the next calculation?
    Last edited by justasiam; April 24th, 2013 at 04:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured