#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
int main()
{
const unsigned quartervalue = 25;
const unsigned dimevalue = 10;
const unsigned nickelvalue = 5;
const unsigned pennyvalue = 1;
std::cout << std::fixed << std::setprecision(2);
// Get a random number from 0-100
srand(time(nullptr));
unsigned change = rand() % 100;
std::cout << "Change Due: $" << (change / 100.0) << "\n";
std::cout << "Coin Dispenser will dispense:\n";
// If change is greater than or equal to one run the program
if (change >= 1) {
unsigned quarter = change / quartervalue;
change = change % quartervalue;
unsigned dime = change / dimevalue;
change = change % dimevalue;
unsigned nickel = change / nickelvalue;
change = change % nickelvalue;
unsigned penny = change;
if (quarter != 0)
std::cout << " Quarters: " << quarter << " ($" <<
(quarter * quartervalue / 100.0) << ")\n";
if (dime != 0)
std::cout << " Dimes: " << dime << " ($" <<
(dime * dimevalue / 100.0) << ")\n";
if (nickel != 0)
std::cout << " Nickels: " << nickel << " ($" <<
(nickel * nickelvalue / 100.0) << ")\n";
if (penny != 0)
std::cout << " Pennies: " << penny << " ($" <<
(penny * pennyvalue / 100.0) << ")\n";
} else {
// If change is = to 0, don't run the entire program, just run this portion.
std::cout << "No Coins\n";
}
}