cash program guidance

-
Last edited on
please put your code in code tags '<>' so it's not a nightmare to read. ill edit this post if i find anything .
-
Last edited on
C++ handles floating point numbers a little strange, but hides it from all of the users. take a look at this:

1
2
3
4
cout.precision(50); //notice the variables printed
    double var = 3.37;
    double var2 = 3.38;
    cout << var << endl << var2 << endl << var2- var;





3.3700000000000001065814103640150278806686401367188
3.3799999999999998934185896359849721193313598632812
0.0099999999999997868371792719699442386627197265625


when multiplying by one 100, the last var wont exactly equal one(thus why one penny always seems to be missing). A fix would be to use ceil() with the entire equation:

int remain = ceil(((tenderP - purchaseP) - (floor(tenderP - purchaseP))) * 100);

Sorry about the late reply, this one was hurting my brain a bit before i finally noticed the conversions from double to int.
-
Last edited on
for future reference, when your topic is finished simply mark is as solved. This way other users can read these topics and learn something, or if this topic pops up in google readers can understand what the question was. No need to restore this post, but keep your future posts in tact.
Topic archived. No new replies allowed.