#include <iostream>
struct Double
{
int characteristic;
char decimal;
int mantissa;
friend std::ostream &operator <<(std::ostream &stm, Double const &rhs)
{
return stm << rhs.characteristic << rhs.decimal << rhs.mantissa;
}
friend std::istream &operator >>(std::istream &stm, Double &rhs)
{
return stm >> rhs.characteristic >> rhs.decimal >> rhs.mantissa;
}
Double operator-(Double const &rhs) const
{
Double result = *this;
if(rhs.mantissa > result.mantissa)
{
--result.characteristic;
result.mantissa += 100;
}
result.characteristic -= rhs.characteristic;
result.mantissa -= rhs.mantissa;
return result;
}
};
int main()
{
Double itemCost;
std::cout << "Please enter the item cost: ";
std::cin >> itemCost;
Double amountPaid;
std::cout << "Please enter the amount paid: ";
std::cin >> amountPaid;
Double change = amountPaid - itemCost;
std::cout << "Change due $" << change << std::endl;
//now you can get the exact change easy
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IERvdWJsZQp7CglpbnQgY2hhcmFjdGVyaXN0aWM7CgljaGFyIGRlY2ltYWw7CglpbnQgbWFudGlzc2E7CgkKCWZyaWVuZCBzdGQ6Om9zdHJlYW0gJm9wZXJhdG9yIDw8KHN0ZDo6b3N0cmVhbSAmc3RtLCBEb3VibGUgY29uc3QgJnJocykKCXsKCQlyZXR1cm4gc3RtIDw8IHJocy5jaGFyYWN0ZXJpc3RpYyA8PCByaHMuZGVjaW1hbCA8PCByaHMubWFudGlzc2E7Cgl9CgkKCWZyaWVuZCBzdGQ6OmlzdHJlYW0gJm9wZXJhdG9yID4+KHN0ZDo6aXN0cmVhbSAmc3RtLCBEb3VibGUgJnJocykKCXsKCQlyZXR1cm4gc3RtID4+IHJocy5jaGFyYWN0ZXJpc3RpYyA+PiByaHMuZGVjaW1hbCA+PiByaHMubWFudGlzc2E7Cgl9CgkKCURvdWJsZSBvcGVyYXRvci0oRG91YmxlIGNvbnN0ICZyaHMpIGNvbnN0Cgl7CgkJRG91YmxlIHJlc3VsdCA9ICp0aGlzOwoJCWlmKHJocy5tYW50aXNzYSA+IH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