# Help coin program.

```#include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; int main() { int const QUARTER = 25; int const NICKEL = 5; int const DIME = 10; int totalQuarters, totalNickels, totalDimes,q,n,d; int currentBalance,amount, change,change2,remainder,changeleft; double totalBalance; ifstream coinIn; cout<<"Vending Machine\n\n"; cout<<"Filling machine with change. Please wait....\n"; coinIn.open("coin.dat"); coinIn >> totalQuarters>>totalDimes>>totalNickels; cout<<"There are "<<totalQuarters<<" quaters, "<<totalDimes<<" Dimes,and "<<totalNickels<<" Nickels."<<endl; currentBalance = (QUARTER * totalQuarters) + (NICKEL * totalNickels) + (DIME * totalDimes); cout<<fixed<<setprecision(2)<<showpoint; cout<<"Initial machine balance is \$"<<currentBalance/100.00<<endl; cout<<"Enter a purchase amount [0-100] -->"; cin>>amount; changeleft = (QUARTER * totalQuarters) + (NICKEL * totalNickels) + (DIME * totalDimes); if (amount >= 0 && amount <= 100) { while (amount != 0) { change = 100-amount; cout<<"\n\nYou entered a purchase amount of "<<amount<<" cents."<<endl; cout<<"Please enter one-dollar bill"<<endl; cout<<"Processing your purchase"<<endl; cout<<"Thank you for your purchase"<<endl; change2 = change; if( totalQuarters != 0 && change2 < changeleft) { q = change2/QUARTER; remainder = change2%QUARTER; totalQuarters -= q; d = remainder / DIME; remainder = remainder%DIME; totalDimes -= d; n = remainder / NICKEL; remainder = remainder%NICKEL; totalNickels -=n; } else if (totalDimes != 0 && change2 < changeleft) { d = change2/ DIME; remainder = remainder%DIME; totalDimes -= d; n = remainder / NICKEL; remainder = remainder%NICKEL; totalNickels -=n; } else if (totalNickels != 0 && change2 < changeleft) { n = change2 / NICKEL; remainder = remainder%NICKEL; totalNickels -=n; } else { cout<<"Insufficient change!\n"; cout<<"Your transaction cannot be processed.\n"; cout<<"Please take back your dollar bill.\n"; cout<<"\n\nEnter a purchase amount [0-100] -->"; cin>>amount; } changeleft = (QUARTER * totalQuarters) + (NICKEL * totalNickels) + (DIME * totalDimes); totalBalance = (changeleft + amount)/100.00; cout<<"Your change of "<<change<<" is given as:"<<endl; cout<<q<<" quaters, "<<d<<" Dimes, and "<<n<<" Nickels ("<<change<<" cents.)"<<endl; cout<<"\n\nEnter a purchase amount [0-100] -->"; cin>>amount; } } else { cout<<"Invalid amount entered, please enter a valid amount\n"; } cout<<"Output file is being generated....\n"; cout<<"Machine is shutting down. Good bye.\n"; ofstream balance; balance.open("machine.txt"); balance<<"Number of quarters: "<<totalQuarters<<endl; balance<<"Number of dimes: "<<totalDimes<<endl; balance<<"Number of nickels: "<<totalNickels<<endl; balance<<fixed<<setprecision(2)<<showpoint; balance<<"Current balance: \$"<<totalBalance<<endl; coinIn.close(); return 0; }```