#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
unsigned change = time(0);
int quarters = 0;
int dime = 0;
int nickel = 0;
int penny = 0;
//Get a random number from 0-100
srand(change);
change = change % 100;
// If change is greater than or equal to one run the program
if (change != 0)
{
// using fixed and set precision to eliminate need for decimal fixing.
cout << fixed << setprecision(2);
cout << "Change Due:" << setw(4) << "$" << change / 100.0 << "\n";
cout << "Coin Dispenser will dispense:\n";
// Calculate and adjust variables
quarters = change / 25;
change = change % 25;
dime = change / 10;
change = change % 10;
nickel = change / 5;
change = change % 5;
penny = change / 1;
if (quarters != 0)
{
cout << " Quarters: " << quarters << " (" << "$" << quarters * 25 / 100.0 << ")" << "\n";
}
if (dime != 0)
{
cout << " Dimes:" << setw(5) << dime << " (" << "$" << dime * 10 / 100.0 << ")" << "\n";
}
if (nickel != 0)
{
cout << " Nickels:" << setw(3) << nickel << " (" << "$" << nickel * 5 / 100.0 << ")" << "\n";
}
if (penny != 0)
{
cout << " Pennies:" << setw(3) << penny << " (" << "$" << penny * 1 / 100.0 << ")" << "\n";
}
}
// If change is = to 0, don't run the entire program, just run this portion.
else
{ cout << "Change Due" << "$0.00" << "\n";
cout << "Coin Dispenser will dispense:\n";
cout << "No Coins\n";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjdGltZT4KIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBtYWluKCkKewogICAgdW5zaWduZWQgY2hhbmdlID0gdGltZSgwKTsKICAgICAgICBpbnQgcXVhcnRlcnMgPSAwOwogICAgICAgIGludCBkaW1lID0gMDsKICAgICAgICBpbnQgbmlja2VsID0gMDsKICAgICAgICBpbnQgcGVubnkgPSAwOwogCiAgICAgICAgLy9HZXQgYSByYW5kb20gbnVtYmVyIGZyb20gMC0xMDAKICAgICAgICBzcmFuZChjaGFuZ2UpOwogICAgICAgIGNoYW5nZSA9IGNoYW5nZSAlIDEwMDsKIAogCiAgICAgICAgLy8gSWYgY2hhbmdlIGlzIGdyZWF0ZXIgdGhhbiBvciBlcXVhbCB0byBvbmUgcnVuIHRoZSBwcm9ncmFtCiAgICAgICAgaWYgKGNoYW5nZSAhPSAwKQogICAgICAgIHsKICAgICAgIAogICAgICAgICAgICAgICAgLy8gdXNpbmcgZml4ZWQgYW5kIHNldCBwcmVjaXNpb24gdG8gZWxpbWluYXRlIG5lZWQgZm9yIGRlY2ltYWwgZml4aW5nLgogICAgICAgICAgICAgICAgY291dCA8PCBmaXhlZCA8PCBzZXRwcmVjaXNpb24oMik7CiAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgY291dCA8PCAiQ2hhbmdlIER1ZToiIDw8IHNldHcoNCkgPDwgIiQiIDw8IGNoYW5nZSAvIDEwMC4wIDw8ICJcbiI7CiAgICAgICAgICAgICAgICBjb3V0IDw8ICJDb2luIERpc3BlbnNlciB3aWxsIGRpc3BlbnNlOlxuIjsKIAogICAgICAgICAgICAgICAgICAgIC8vIENhbGN1bGF0ZSBhbmQgYWRqdXN0IHZhcmlhYmxlcwogICAgICAgICAgICAgICAgICAgICAgICBxdWFydGVycyA9IGNoYW5nZSAvIDI1OwogICAgICAgICAgICAgICAgICAgICAgICBjaGFuZ2UgPSBjaGFuZ2UgJSAyNTsKICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgZGltZSA9IGNoYW5nZSAvIDEwOwogICAgICAgICAgICAgICAgICAgICAgICBjaGFuZ2UgPSBjaGFuZ2UgJSAxMDsKICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIG5pY2tlbCA9IGNoYW5nZSAvIDU7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoYW5nZSA9IGNoYW5nZSAlIDU7CiAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIHBlbm55ID0gY2hhbmdlIC8gMTsKIAogICAgICAgICAgICAgICAgICAgICAgICBpZiAocXVhcnRlcnMgIT0gMCkKICAgICAgICAgICAgICAgICAgICAgICAgeyAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY291dCA8PCAiIFF1YXJ0ZXJzOiAiIDw8IHF1YXJ0ZXJzIDw8ICIgKCIgPDwgIiQiIDw8IHF1YXJ0ZXJzICogMjUgLyAxMDAuMCA8PCAiKSIgPDwgIlxuIjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpbWUgIT0gMCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICIgRGltZXM6IiA8PCBzZXR3KDUpIDw8IGRpbWUgPDwgIiAoIiA8PCAiJCIgPDwgZGltZSAqIDEwIC8gMTAwLjAgPDwgIikiIDw8ICJcbiI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogCiAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChuaWNrZWwgIT0gMCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY291dCA8PCAiIE5pY2tlbHM6IiA8PCBzZXR3KDMpIDw8IG5pY2tlbCA8PCAiICgiIDw8ICIkIiA8PCBuaWNrZWwgKiA1IC8gMTAwLjAgPDwgIikiIDw8ICJcbiI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAKICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZW5ueSAhPSAwKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICIgUGVubmllczoiIDw8IHNldHcoMykgPDwgcGVubnkgPDwgIiAoIiA8PCAiJCIgPDwgcGVubnkgKiAxIC8gMTAwLjAgPDwgIikiIDw8ICJcbiI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgLy8gSWYgY2hhbmdlIGlzID0gdG8gMCwgZG9uJ3QgcnVuIHRoZSBlbnRpcmUgcHJvZ3JhbSwganVzdCBydW4gdGhpcyBwb3J0aW9uLgogICAgICAgIGVsc2UgIAogICAgICAgIHsgICAgICAgY291dCA8PCAiQ2hhbmdlIER1ZSIgPDwgIiQwLjAwIiA8PCAiXG4iOwogICAgICAgICAgICAgICAgY291dCA8PCAiQ29pbiBEaXNwZW5zZXIgd2lsbCBkaXNwZW5zZTpcbiI7CiAgICAgICAgICAgICAgICBjb3V0IDw8ICJObyBDb2luc1xuIjsKICAgICAgICB9CiAKfQ==