This is my first time posting here, so if the code is too long, I'll be more than happy to edit it.
I'm making a cashier, a function that makes change.
The odd thing is: If I buy 1.14 for 1.15, I get a penny back. But if I buy .14 for .15 I get no pennies back.
Also, if I buy .15 for .20, I get a nickel back. But if I buy .20 for .25, I get 4 pennies back. I need help understanding why I'm getting four pennies back instead of 0 pennies and 1 nickel like I'm supposed to. I believe something has to be wrong with the division somewhere.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double buyAmount = 0.0;
double paidAmount = 0.0;
double diffAmount = 0.0;
double smallChange = 0.0;
int dollars = 0;
int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;
cout << "Enter purchase amount: ";
cin >> buyAmount;
cout << endl;
cout << "Enter paid amount: ";
cin >> paidAmount;
cout << endl;
diffAmount = paidAmount - buyAmount;
if (diffAmount < 0 ) {
cout << "Error: Make sure paid amount exceeds purchase amount. ";
cout << endl;
}
dollars = floor(diffAmount);
smallChange = (diffAmount - dollars) * 100
quarters = (smallChange / 25);
smallChange = smallChange - (quarters * 25);
dimes = (smallChange / 10);
smallChange = smallChange - (dimes * 10);
nickels = floor(smallChange / 5);
smallChange = smallChange - (nickels * 5);
pennies = floor(smallChange / 1);
cout << "Total Change: $" << diffAmount;
cout << endl << endl;
cout << "dollars " << dollars << endl;
cout << "quarters " << quarters << endl;
cout << "dimes " << dimes << endl;
cout << "nickels " << nickels << endl;
cout << "pennies " << pennies << endl;
}