Secondly, use modf, as I mentioned above. Makes it pretty trivial:
#include <iostream>
#include <string>
int main() {
float decimal_pounds;
std::cout << "Enter decimal pounds: ";
std::cin >> decimal_pounds;
float pounds, shillings, pennies;
float remainder;
remainder = modf(decimal_pounds, £s);
remainder *= 20.0; //convert to shillings
remainder = modf(remainder, &shillings);
remainder *= 12.0; //convert to pennies
remainder = modf(remainder, &pennies);
std::cout<<pounds<<" - "<<shillings<<" - "<<pennies<<" - "<<remainder<<std::endl;
return 0;
}
Take note that if you use a value like 12.23 you get a result out with a remainder whose value is NOT the expected 0.2, but will be a value close to 0.2! This is due to floating point errors.As an additional note, if you accumulate those lost decimal points into an account... you end up having to burn down your place of work and take up construction.