Making Change out of an XX.XX input

I'm not going to lie, I need help with my homework for my college Programming class. I've done all of this work myself, but there are some inputs that aren't working right.
The purpose of the program is to be able to accept input like 16.45 and the like. The program then returns the denominations of money needed to make change, i.e. twenties, tens, fives, ones, quarters, dimes, nickels, and pennies. For some reason, the total of 1200.86 will not work. Here is my code, please help.

#include <iostream>

using namespace std;

const int TWENTIES = 2000;
const int TENS = 1000;
const int FIVES = 500;
const int ONES = 100;
const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;

int main()
{
float change;

int totalMoneyInPennies;

cout << "This program will convert a total amount of money into denominations of money to make change." << endl;
cout << "Input the total here: ";
cin >> change;
cout << endl;

totalMoneyInPennies = (change * 100);

cout << "You input: $" << change << ".";
cout << endl;

cout << "This is a total of " << totalMoneyInPennies << " pennies.";
cout << endl;

cout << "Your denominations would be: " << endl;

cout << "Twenties: "
<< totalMoneyInPennies / TWENTIES
<< endl;

totalMoneyInPennies = totalMoneyInPennies % TWENTIES;

cout << "Tens: "
<< totalMoneyInPennies / TENS
<< endl;

totalMoneyInPennies = totalMoneyInPennies % TENS;

cout << "Fives: "
<< totalMoneyInPennies / FIVES
<< endl;

totalMoneyInPennies = totalMoneyInPennies % FIVES;

cout << "Ones: "
<< totalMoneyInPennies / ONES
<< endl;

totalMoneyInPennies = totalMoneyInPennies % ONES;

cout << "Quarters: "
<< totalMoneyInPennies / QUARTER
<< endl;

totalMoneyInPennies = totalMoneyInPennies % QUARTER;

cout << "Dimes: "
<< totalMoneyInPennies / DIME
<< endl;

totalMoneyInPennies = totalMoneyInPennies % DIME;

cout << "Nickels: "
<< totalMoneyInPennies / NICKEL
<< endl;

totalMoneyInPennies = totalMoneyInPennies % NICKEL;

cout << "Pennies: "
<< totalMoneyInPennies << endl;

return 0;
}
Worked right for me. 60 twenties, three quarters, a dime and a penny.
I compiled it using MS Visual C++ 2008 Express, and found that starting at the amount of pennies that made up the input, was always one cent off. So, I changed totalMoneyInPennies = (change * 100); to totalMoneyInPennies = 1+(change * 100);, and then everything was coming out correctly, right down to the penny.
Really? That's very strange. I double checked the program on my system (a Mac) and it works fine as is.

I wonder if you're running into some obscure conversion error in your float representation. I seem to recall that decimal fractions don't always store well in binary format. Still, I'd expect your CPU to be similar to mine.

I don't know what to think about this one...
My freaking Google account got canceled so I had to make a new one.

I figured it out, though. Thanks for the responses though. Mzimmers, you were right. It was a problem with the binary and fractions. I got it figured out though.

#include <iostream>

using namespace std;

const int TWENTIES = 2000;
const int TENS = 1000;
const int FIVES = 500;
const int ONES = 100;
const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;
const int PENNIES_TO_DOLLAR = 100;

int main()
{
int DollarAmt, DecimalAmt;
char DecimalPoint;

int totalMoneyInPennies;

cout << "This program will convert a total amount of money into denominations of money to make change." << endl;
cout << "Input the total here: ";
cin >> DollarAmt >> DecimalPoint >> DecimalAmt;
cout << endl;

totalMoneyInPennies = DecimalAmt + (DollarAmt * PENNIES_TO_DOLLAR);

cout << "You input: $" << DollarAmt << DecimalPoint << DecimalAmt << ".";
cout << endl;

cout << "This is a total of " << totalMoneyInPennies << " pennies.";
cout << endl;

cout << "Your denominations would be: " << endl;

cout << "Twenties: "
<< totalMoneyInPennies / TWENTIES
<< endl;

totalMoneyInPennies = totalMoneyInPennies % TWENTIES;

cout << "Tens: "
<< totalMoneyInPennies / TENS
<< endl;

totalMoneyInPennies = totalMoneyInPennies % TENS;

cout << "Fives: "
<< totalMoneyInPennies / FIVES
<< endl;

totalMoneyInPennies = totalMoneyInPennies % FIVES;

cout << "Ones: "
<< totalMoneyInPennies / ONES
<< endl;

totalMoneyInPennies = totalMoneyInPennies % ONES;

cout << "Quarters: "
<< totalMoneyInPennies / QUARTER
<< endl;

totalMoneyInPennies = totalMoneyInPennies % QUARTER;

cout << "Dimes: "
<< totalMoneyInPennies / DIME
<< endl;

totalMoneyInPennies = totalMoneyInPennies % DIME;

cout << "Nickels: "
<< totalMoneyInPennies / NICKEL
<< endl;

totalMoneyInPennies = totalMoneyInPennies % NICKEL;

cout << "Pennies: "
<< totalMoneyInPennies << endl;

return 0;
}

try this one.
No point in my trying it, since the original worked fine on my system.

In the future, please put your code into code tags; it makes it much easier to read and copy.

Glad you got it working...
Well, I tried it out, and, yes, it worked flawlessly, right down to the penny. No adjustments on may part, as I had to do in the original. Great job, Johnston. I even added in Fifties, to the list of change.
Topic archived. No new replies allowed.