#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <vector>

struct coin
{
    coin(std::string name_, int value_) : value(value_), name(name_) {}
    unsigned value;
    std::string name;
};

bool operator<(const coin& lhs, const coin& rhs)
{
    return lhs.value < rhs.value;
}

int main()
{
    std::vector<std::pair<coin, int>> money = { //Coin data and amount
        {{"Quarter", 25}, 0}, {{"Dime", 10}, 0}, {{"Nickel", 5}, 0}, {{"Penny", 1}, 0}
    };
    std::sort(money.begin(), money.end(), std::greater<std::pair<coin, int>>());

    srand(time(nullptr));
    unsigned change = rand() % 100;

    std::cout << std::fixed << std::setprecision(2);
    std::cout << "Change Due:   $" << (change / 100.0) << "\n";
    std::cout << "Coin Dispenser will dispense:\n";
    if (change == 0) {
        std::cout << "No Coins\n";
        return 0;
    }
    for(auto& data: money)  {
        data.second = change / data.first.value;
        change %= data.first.value;
    }
    for(const auto& data: money) {
        if (data.second != 0)
            std::cout << std::left << std::setw(11) <<
                      (" " + data.first.name + ":") << data.second <<
                      " ($" << (data.second * data.first.value / 100.0) << ")\n";
    }
}
