I have an assignment where the user enters some money, and it supposed to give them the number of bills and coins they need, but I am stuck in the storing the change and getting the amount of change required.
The issue I have is I know I can't store coins as an integer, but if I try storing it as a double, it gets the error that is %mod can't be used with a double. Is there a way to extract the remainder once the initial bills have been accounted? With a double
The way it currently is if I enter 456.56 I will get 4 hundred dollar bills, 2 twenties, 1 ten etc. but nothing about the .56
/*This program will convert the amount of money entered by the user into the amount of bills and change*/
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
const int HUNDRED = 100;
const int TWENTY = 20;
const int TEN = 10;
const int FIVE = 5;
const int DOLLAR = 1;
const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 05;
const int PENNY = 01;
int changeAmount;
cout << "Enter amount of money to convert: $";
cin >> changeAmount;
cout << "\n";
cout << "Numbe of 100 dollar bills: " << (int)changeAmount / HUNDRED << endl;
changeAmount = changeAmount % HUNDRED;
cout << "Numbe of 20 dollar bills: " << (int)changeAmount / TWENTY << endl;
changeAmount = changeAmount % TWENTY;
cout << "Numbe of 10 dollar bills: " << (int)changeAmount / TEN << endl;
changeAmount = changeAmount % TEN;
cout << "Numbe of 5 dollar bills: " << (int)changeAmount / FIVE << endl;
changeAmount = changeAmount % FIVE;
cout << "Numbe of 1 dollar bills: " << (int)changeAmount / DOLLAR << endl;
changeAmount = changeAmount % DOLLAR;
cout << "Numbe of Quarters: " << (int)changeAmount / QUARTER << endl;
changeAmount = changeAmount % QUARTER;
cout << "Numbe of Dimes: " << (int)changeAmount / DIME << endl;
changeAmount = changeAmount % DIME;
cout << "Numbe of Nickles: " << (int)changeAmount / NICKEL << endl;
changeAmount = changeAmount % NICKEL;
cout << "Numbe of Pennies: " << (int)changeAmount / PENNY << endl;
changeAmount = changeAmount % PENNY;
return 0;
}